Should i store deeply nested data in plain objects or a class?
Unanswered
Japanese common catfish posted this in #help-forum
Japanese common catfishOP
So I find myself calling:
all over the code base. So I was thinking whether I should create a class with methods like
setCurrentWorkout(
produce(currentWorkout, (draft) => {
draft.name = e.currentTarget.value;
}),
)all over the code base. So I was thinking whether I should create a class with methods like
.setName so that I can simplify data manipulation.7 Replies
Japanese common catfishOP
But i saw this answer: https://stackoverflow.com/a/71874663/11667450
and started debating whther this is the correct way to go?
and started debating whther this is the correct way to go?
@Japanese common catfish So I find myself calling:
setCurrentWorkout(
produce(currentWorkout, (draft) => {
draft.name = e.currentTarget.value;
}),
)
all over the code base. So I was thinking whether I should create a class with methods like `.setName` so that I can simplify data manipulation.
seems like you are already using
your example would become
immer, then why not use use-immer? makes things like this very simple. https://github.com/immerjs/use-immeryour example would become
setCurrentWorkout(draft => {
draft.name = e.currentTarget.value;
});@joulev seems like you are already using `immer`, then why not use `use-immer`? makes things like this very simple. <https://github.com/immerjs/use-immer>
your example would become
tsx
setCurrentWorkout(draft => {
draft.name = e.currentTarget.value;
});
Japanese common catfishOP
i am also using jotai
would that change things?
@joulev try this then <https://jotai.org/docs/extensions/immer>
Japanese common catfishOP
im already using
atomWithStorage so this wont be possibleThen I don’t know, sorry. I don’t use jotai.