Started playing around with atomFamily and selectorFamily (thanks to @tony-go's PR branch) but when trying to replace my individual atom and selector lookups with the associated family functions I am getting errors like:
Error: Missing definition for RecoilValue: "questionFamily__1__withFallback""
I am assuming this is developer error, but I'm not sure what I'm doing wrong. Here is what my atomFamily looks like.
const questionById = buildHash() // omitting for brevity, but it's what it looks like!
const questionState = atomFamily({
key: "questionFamily",
default: (id) => {
const item = questionById[id]
return {
type: item.type,
label: item.label,
value: item.value
}
}
});
const questionDB = {
questionSequence: [... all question ids in sequence ],
questionState
}
export questionDB
I then put this in a ReactContext to be able to get to it from other components.
<RecoilRoot>
<SurveyContext.Provider value={questionDB}>
{
questionDB.questionSequence.map((id) => {
return (
<Question key={id} questionId={id} />)
})
}
</SurveyContext.Provider>
</RecoilRoot>
Inside my Question component I have:
const Question = (props) => {
const questionDb = useContext(SurveyContext)
const id = props.questionId
const [questionState, setQuestionState] = useRecoilState(questionDb.questionState(id))
return ( /* components */)
}
It's the useRecoilState line where the error is being thrown. Feels like I'm probably messing something up with variable scoping or by using the ReactContext to pass it around, but I'm not sure what the right way to fix it is.
I had the same error, I was waiting for it to be published before I made an issue, since I wasn't sure if it was something to do with the branch or not.
cc @mondaychen
I tried creating an atom whose default value was a promise which gave me an exception of selector is not defined when it tries to create the atomWithFallback. I suspect this is the root cause of this.
Should be fixed with 0.0.8
Still getting this error when trying to use a Promise for default atom value:
my recoil version: "recoil": "^0.0.8",
recoil.development.js:200 Uncaught Error: Missing definition for RecoilValue: "undefined""
Most helpful comment
I tried creating an atom whose default value was a promise which gave me an exception of
selector is not definedwhen it tries to create theatomWithFallback. I suspect this is the root cause of this.