[React] Directly Dispatch Actions into the Redux Store Before React Renders
This lesson demonstrates that you can get a small performance gain by removing AJAX calls that feed into redux from the react/hooks lifecycle. In this video we see a 100ms reduction in the time it takes to initiate our AJAX call to load AJAX rates when we move it outside of useEffect
and into our index.js file.
A thorough look at some of these patterns can be found here: https://redux.js.org/tutorials/essentials/part-5-async-logic
Documentation for all of the methods available on our redux store including dispatch
and getState
can be found here: https://redux.js.org/api/store/#store-methods-1
Note: If you want to keep the logic inside of the useEffect
and still get the performance benefit you kick off your API calls somewhere and store the generated promise somewhere and pick that up in your useEffect
hook.
Syntax:
const store = configureStore({ reducer: counterReducer }) const exampleThunkFunction = (dispatch, getState) => { const stateBefore = getState() dispatch(increment()) } store.dispatch(exampleThunkFunction)
Dispatch async event for initial state can be done outside of component. Can do it in index.js file before rendering anything.
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
2020-04-11 [RxJS] Extend Promises by Adding Custom Behavior
2019-04-11 [Algorithm] Binary tree: Level Order Traversal
2019-04-11 [SSH] Intro to SSH command
2018-04-11 [Tailwind] Extending Tailwind with Responsive Custom Utility Classes
2018-04-11 [Tailwind] Control What Variations are Generated for Each Utility Class Module in Tailwind
2016-04-11 [RxJS] Creation operator: of()