-
Hi, I'm trying to use React Router in my React Vite app testing my page with a loader but it comes with a warning on the loader const name: I couldn't figure out what it means and how to fix it. Can you help me on understand it and where I'm wrong? import { useEffect } from "react";
import { useLoaderData, Form, redirect, useParams } from "react-router-dom";
export const loader = ({ params }: any) => async () => {
const note = params.noteId;
console.log("note1: ", note);
if (!note) throw new Response("", { status: 404 });
return note;
};
export default function NotePage() {
const note = useLoaderData();
console.log("note2: ", note);
return (
<div>
Note Test
</div>
);
} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 10 replies
-
Hey! You are exporting both a component and a function from the same file. Fast Refresh only works, when you're exporting components exclusively. For Fast Refresh to work, you need to put your |
Beta Was this translation helpful? Give feedback.
-
This seems to work for me in .eslintrc.cjs: module.exports = {
rules: {
"react-refresh/only-export-components": [
"warn",
{ allowExportNames: ["loader"] },
],
},
}; See https://github.com/ArnaudBarre/eslint-plugin-react-refresh?tab=readme-ov-file#allowexportnames-v044. |
Beta Was this translation helpful? Give feedback.
Hey! You are exporting both a component and a function from the same file. Fast Refresh only works, when you're exporting components exclusively. For Fast Refresh to work, you need to put your
NotePage
Component and theloader
into different files, e.g.,notepage.element.tsx
andnotepage.loader.ts
.