A
A
Azad Kichibekov2020-11-15 11:00:11
React
Azad Kichibekov, 2020-11-15 11:00:11

Better store or state?

Let's say I have 2 main.js and table.js files, how best to transfer table data to table.js? through redux actions, network and edit the table, or through props, throw set functions and the table data itself there

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vlad_Murashchenko, 2020-11-15
@rally08

Prefer to keep the state as close as possible to the location that uses it. This will allow you to better divide the responsibilities between the components. Based on this principle:
If the state of your table is needed only in the table, then it is best to receive and store the state of your table directly in the "container" component (the component that knows what this particular table is about, and not just displays an abstract table).
If your table data is used elsewhere, you need to move the state to the level of the general "container" of the component.
Redux is suitable if the data is used by different parts of the application that are far from each other (for example, on different pages). If you want the data not to be fetched from memory after the user closes the component. If you need Flux, transactions, deterministic state management... But for displaying table data, you probably don't need it.
Remember about KISS, YAGNI - they help a lot in decision making

V
Vasily, 2020-11-18
@vasily_konnov

Depends on the logic of interaction between components (architecture) if table.js receives props from main.js then skip props and enjoy life, if this table is called in different components that are not directly tied to props, but should work with one state (component state) then Redux, Mobx

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question