Closed MiloshN closed 5 years ago
Actions are just plain javascript objects like{ type: 'foo' }
or { type: 'foo', payload: { bar: 1 } }
.
It's up to you how/where you declare their types and/or create them. They work exactly the same as in Redux or useReducer
hook. React-tracked does not have any difference when it comes to handling actions that I'm aware of, except dispatching objects from state (but that is outside the scope of your question).
You could import an action / action type / action creator from another file, hardcode it in a dispatch function call (dispatch({type: 'foo', payload: {...} })
) or any other approach possible in Javascript.
Yes, it is possible. You can use Redux pattern if you like.
My proposition (or one of my propositions at this moment) is to use custom hooks to dispatch actions. See the blog post and the code.
As a side note, I like to use custom hooks in React Redux too: https://blog.axlight.com/posts/react-hooks-oriented-redux-coding-pattern-without-thunks-and-action-creators/
Let me close this issue. @MiloshN Feel free to reopen it if you have questions related to this.
Is it possible and how, to create actions in react-tracked folder structure? Redux pattern?
Points are to create action and share them between components. In the documentation, are action only in one component?