[Question] Readable atom with parameter or Another way
See original GitHub issueThank for great works.
I have some question, I develop custom calendar component.
Calendar component have selection map, for example:
// row are number of weekday, col are 7
const calendarSelectionMap: boolean[][] = [];
But, Calendar component don’t know user selected month so dynamic generation array on render time.
// phase 01, create component
const [state, dispatch] = useReducerAtom(mainAtom, reducer);
const rowCount: number = calculateCalendarRowCount(userSelectedMonth);
const days = calculateCalendarDay(userSelectedMonth);
useLayoutEffect(() => {
// phase02 initialize component state
dispatch({ type: 'create-selection-map', rowCount })
}, [ state, dispatch ]);
// phase03 render dom: only example
return (
{_.times(rowCount).map((rowId) => {
<div>
{_.times(7).map((colId) => <div selected={{state.selection[rowId][colId]}}>{days[rowId][colId]}</div>
</div>
})}
);
but I got exception phase03, react SSR executed phase01 -> 03 -> 02.
I solve this problem that create wrapper function.
const onGetSelection = useCallback((rowId: number, colId: nubmer) => {
try {
return state.selection[rowId][colId];
} catch {
return false;
}
}, [state])
But I want use state value direct below,
<div selected={{state.selection[rowId][colId]}}>{days[rowId][colId]}</div>
So, I Think that
const readableAtom = atom(mainAtom, (get, param) => {
const state = get(mainAtom);
try {
return state.selection[param.rowId][param.colId];
} catch {
return false;
}
});
But I can’t found readable atom with any parameter. I miss understood mechanism?
Thank you for kindness
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
10 Essential Atom Editor Packages & Setup - YouTube
In this video I will start with a default Atom editor and add each of my favorite packages and plugins step by step...
Read more >Problem to use prot_na.prm with cgenff.prm - CHARMM forums
Currently, whenever one attempts to combine one RTF/PARAM pair with another in CHARMM, it is necessary to make sure that both the atom...
Read more >What is the use case of atomFamily in recoil? - Stack Overflow
When you call atomFamily() it will return a function which provides the RecoilState atom based on the parameters you pass in.
Read more >258 questions with answers in CHARMM | Science topic
I would like to have the vdw force field parameters of different phosphate and ... I read that GROMACS has an option for...
Read more >variable command - LAMMPS documentation
variable start timer other commands variable stop timer print "Elapsed ... Each time a set of per-atom values is read, a non-blank line...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I wouldn’t at this point, as it’s not the primary recommendation. BUT, it might turn out to be something good with possibly other practice, so I will keep that in mind.
Let me leave another pattern with a custom hook, which may seem more idiomatic (not explicitly suggesting it, but just to expand our ideas):
@dai-shi
Thank you for your answer.
Great! that is perfect solution for my case. I don’t think that readable atom will be able to function.
Very helpful talk.
Maybe, I think your example
getTodoItemAtom
is add to primitives document it is great helpful content.Thank you!