Skip to content

Commit 6530efb

Browse files
committed
refactor: file fetching logic in LiveHtmlEditor component
1 parent be4033b commit 6530efb

File tree

1 file changed

+2
-13
lines changed

1 file changed

+2
-13
lines changed

src/components/LiveHtmlEditor.jsx

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,8 @@ export default function LiveHtmlEditor({ fileUrl }) {
2222
setCode(text);
2323
setLoading(false);
2424
} else if (response.status === 404) {
25-
// Remove the last directory from the url
26-
const directoryUrl = url.substring(0, url.lastIndexOf('/'));
27-
28-
// Recursively try to fetch the file from the parent directory
29-
fetchFile(`${directoryUrl}/${filename}`);
25+
// Try to fetch the file from the root of the examples directory
26+
fetchFile(`/examples/${filename}`);
3027
} else {
3128
throw new Error(`HTTP error! status: ${response.status}`);
3229
}
@@ -38,14 +35,6 @@ export default function LiveHtmlEditor({ fileUrl }) {
3835
setLoading(false);
3936
});
4037
}, [fileUrl, fetchFile]);
41-
42-
useEffect(() => {
43-
fetchFile(fileUrl).catch(error => {
44-
setError(error.message);
45-
setLoading(false);
46-
});
47-
}, [fileUrl, fetchFile]);
48-
4938

5039
if (loading) {
5140
return <div>Loading...</div>;

0 commit comments

Comments
 (0)