Error: Missing definition for RecoilValue
See original GitHub issueStarted 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.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top GitHub Comments
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 theatomWithFallback
. I suspect this is the root cause of this.Still getting this error when trying to use a Promise for default atom value:
my recoil version: “recoil”: “^0.0.8”,