I want to import a custom hook I just created named useLocalStorage
but i’ve been getting this error:
The requested module ‘/src/hooks/useLocalStorage.jsx?t=1688798057310’ does not provide an export named ‘useLocalStorage’ (at App.jsx:12:10)___
This is the export statement
export default function useLocalStorage(key, value) {
const saveValue = () => {
localStorage.setItem(key, value)
}
return saveValue
}
This is the import statement
import { useLocalStorage } from './hooks/useLocalStorage'
3
Answers
then :
OR
then:
You are using
export default ...
which doesn’t create a named export. Thus you cannot use it like a named export. (See the docs for details)Either change the import to
to import your default export as
useLocalStorage
or change your export to
to create a named export.
the import statement is trying to import a named export called useLocalStorage from the module /src/hooks/useLocalStorage.jsx?t=1688798057310, but that module does not provide a named export with that name. Instead, it provides a default export which is the function useLocalStorage.
To fix this error, you can change the import statement to:
This will import the default export of the module which is the useLocalStorage function.