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
Hi there, I've been using Jotai since 2023 and loving it.
In my use case, I mostly use derived atoms and some selectAtom for specific cases.
I'm constantly getting and updating data in a nested tree object, focusing on a key.
My question is, is this a good method to handle large objects, or is there a better approach?
My current implementation example (more or less like this)
typeApp={id: string,pages: {id: string,pathname: string,content: {id: string,components: {id: string,type: string,data: {id: string,value: string}[]}[]}}[]}constappAtom=atom<App>("contentIsHere")constpagesAtom=atom(get=>get(appAtom).pages)constpageSelectedIdAtom=atom("")constpageSelectedDetailAtom=atom(get=>get(pagesAtom).find(a=>a.id===get(pageSelectedIdAtom)),(get,set,id,value)=>{// Currently either using immer for updateconstcurrentPagesImmer=get(pagesAtom)set(appAtom,produce(currentPagesImmer,draft=>{constindex=draft.findIndex(a=>a.id===id)if(index!==-1){draft[index]=value}}))// OR using normal updateconstcurrentPagesNormal=get(pagesAtom)constcurrentPageIndex=currentPagesNormal.findIndex(a=>a.id===id)if(currentPageIndex!==-1){currentPagesNormal[currentPageIndex]=valueset(appAtom,{
...currentPages,pages: currentPagesNormal})}})constcomponentSelectedIdAtom=atom("")constcomponentSelectedDetailAtom=atom(get=>get(pageSelectedDetailAtom)?.content.components.find(a=>a.id===get(componentSelectedIdAtom)),(get,set,id,value)=>{constcurrentPage=get(pageSelectedDetailAtom)set(pageSelectedDetailAtom,produce(currentPage,draft=>{constcomponent=draft?.content.components.find(a=>a.id===id)component&&Object.assign(component,value)}))})constcomponentSelectedDetailDataAtom=atom(get=>get(componentSelectedDetailAtom)?.data,(get,set,id,value)=>{constcurrentComponent=get(componentSelectedDetailAtom)set(componentSelectedDetailAtom,produce(currentComponent,draft=>{draft.data={
...draft?.data,
...value}}))})
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi there, I've been using Jotai since 2023 and loving it.
In my use case, I mostly use derived atoms and some selectAtom for specific cases.
I'm constantly getting and updating data in a nested tree object, focusing on a key.
My question is, is this a good method to handle large objects, or is there a better approach?
My current implementation example (more or less like this)
Beta Was this translation helpful? Give feedback.
All reactions