You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to create atoms from an array using split atom, but I get typescript and TypeError: todoAtoms.map is not a function.
Below is the code that I used :
In file appStateAtom.ts, I have a declared atoms
// In response from server I get the below todo object. Here, I am using it directly(mocked) for simplicityexportconsttodo=[{task: 'help the town',done: false,},{task: 'feed the dragon',done: false,},]exportconsttodoStateAtom=atom([]astypeoftodo)exportconsttodoAtomsAtom=atom([])
In file appDispatcher.ts, I set this atom
constfetchTodoAtom=atom(null,async(_get,set)=>{try{constfetchTodoRes=awaitfetchTodo()// here I make api call// items are first populated from a server requestset(todoStateAtom,fetchTodoRes.data)}catch(error){console.log(error)})constsetupTodoAtom=atom((get)=>get(todoTableDataAtom),async(_get,set)=>{try{awaitset(fetchTodoAtom)set(todoAtomsAtom,splitAtom(todoStateAtom))// I get typescript error here}catch(error){console.log(error)}},)
I am trying to create atoms from an array using split atom, but I get typescript and
TypeError: todoAtoms.map is not a function
.Below is the code that I used :
In file appStateAtom.ts, I have a declared atoms
In file appDispatcher.ts, I set this atom
Then I want to use
todoAtomsAtom
in my componentWhere I do
set(todoAtomsAtom, splitAtom(todoStateAtom))
, I get errorAnd Inside my component I get error
Where am I going wrong?
The text was updated successfully, but these errors were encountered: