import-js icon indicating copy to clipboard operation
import-js copied to clipboard

React hooks not found

Open mikabytes opened this issue 5 years ago • 3 comments

  const value = useContext(Context)

useContext doesn't get imported. If I use fixWord, it says No JS module to import for useContext

However when I add it manuallly all works just fine.

This is using React 16.7.0-alpha.2

mikabytes avatar Nov 30 '18 12:11 mikabytes

Confirmed that specifying them manually in config solves the issue.

.importjs.js

module.exports = {
  namedExports: {
    'react': ['useState', 'useEffect', 'useContext', 'useReducer', 'useCallback', 'useMemo', 'useRef', 'useImperativeMethods', 'useLayoutEffect']
  }
}

mikabytes avatar Nov 30 '18 12:11 mikabytes

can it just work as well, but not set the namedExports config ?

iahu avatar Nov 03 '20 06:11 iahu

Well, not at the time when I created this issue. I have since stopped using React, so I don't know if it has been solved since then.

mikabytes avatar Nov 03 '20 07:11 mikabytes

This is still an issue with React 18.2 and ImportJS 5.1. It just can't determine that the react module exports those methods for some reason.

mikabytes avatar Feb 03 '24 08:02 mikabytes

Pretty sure this is due to #344

Closing this in favor of keeping discussion over there.

mikabytes avatar Feb 07 '24 10:02 mikabytes