Search code examples
reactjsreact-state-managementrecoiljs

recoil__WEBPACK_IMPORTED_MODULE_0___default(...) is not a function


I was writing this simple atom

const userState = atom({
  key: "userState",
  default: {},
});

then I got this error recoil__WEBPACK_IMPORTED_MODULE_0___default(...) is not a function when I try to use that atom

const [user, setUser] = useRecoilState(userState);

update: when I updated to 0.0.13 I got this error instead Object(...) is not a function


Solution

  • I should have used brackets to import atom and useRecoilState that solved my issue. Which means

    import {atom} from "recoil" // in atom file
    import {useRecoilState} from "recoil" // in component/s file/s