3 ms·
Right, so let's say your state looks like this: {customers:[{name:"bob",age:21,id:345},{name:"lisa",age:22,id:2992}],selected_customer:345} Now, in this UI if
by drcode 11y ago
Right, so let's say your state looks like this:
{customers:[{name:"bob",age:21,id:345},{name:"lisa",age:22,id:2992}],selected_customer:345}
Now, in this UI if "bob" is selected that's all you see. So the intermediary JSON looks like this:
{customer:{name:"bob",age:21}}
Since neither the internal UI, the full customer list, nor the selection cursor are visible at this point in the UI, all that info can be preprocessed and omitted, leaving only the bare UI-relevant information.
You are right though, many people use "props" in a way that overlaps with what I'm proposing... If you were to write an app where 100% of data is stuffed into props for all components (including the root component) with no direct reference to the state, it would be similar to my suggested approach.
- guscost 11y agoAh, OK, thanks. Although all my components below the top level receive everything as props rather than referencing the application state directly, I do have cases where some props may or may not be used depending on whether some UI is visible. I've thought maybe it means I should break up those components into sub-components but your suggestion might be a good alternative.