@Junjiequan
Posted
I have used redux, redux-tookilt and redux-thunk for my previous projects.
For me, redux only get complicate when the architecture is not planned thoroughly. In other words, when you are going to use redux it is better to have clear understanding regards to how many state changing activities is need to be included.
The initial step for setting up redux logic is the most difficult & complicated part for me not the code itself make the process complicate. Once the initial setup is done, it makes the whole process much more effective and easy to maintain with useSelector and useDispatch hook, you can always add additional reducers & actions effortlessly.
Lastly, I strongly recommend to tryout redux-thunk. It is a middleware that allows to return a function. Its really usefull when your project is required to interact with server-side, e.g., you could use it to GET data from API and use returned data to dispatch actions, example code below:
export const fetchPosts = () => axios.get(http://localhost:5000/posts);
export const fetchAllPosts = async (dispatch: AppDispatch) => {
try {
const { data } = await fetchPosts();
dispatch({ type: "FETCH_ALL", payload: data });
} catch (err: any) {
console.log(err.message);
}
};
This is just my opinion, I wouldn't consider too much about time spend on a project when I am learning. The more time you spend usually means the more you considerate about the project. For me, it is harder to create good quality project with more time than creepy quality with less time, eye on details require a lot of patient and extra efforts.
Hope this feedback helps.
Marked as helpful
@JamesTheLessFC
Posted
@a331998513 Thanks so much for the advice! I have used redux before, including redux-thunk, but it seemed like overkill on this project so that's why I opted for React's Context API instead. I do agree that once redux is set up, it's actually pretty simple. And the Redux dev tools are very helpful for debugging.