Where can I put the complicated logics when using reactjs to be easy to test with Jasmine? Should I put them in Reactjs components? Should I create a separated JS module and include it to components by props? Should I put it in Flux store?
1 Answers
There're many ways to share the logics among components, and it depends on your scenario and design. Let's say you have Book
state in your BookStore
. You need to access multiple APIs, get responses and merge them into a Book
state object. The logic you merge the responses could be defined in the BookStore
, and every component can use the Book
state without worrying about converting objects. Because the conversion logic is only defined in the BookStore
, it helps you test the logic easily.
So, if your 'complicated logics' mean how you transform data into state, put them in the stores. If they mean how you retrieve your data, put them in your actions. If the logics mean how you process states and affect the UI, put them in your component. If that logics are shared among components, create a separated JS module.

- 725
- 1
- 4
- 12