react-boilerplate/redux-injectors hiện có 128 sao trên GitHub, viết chủ yếu bằng JavaScript. Asynchronous injectors for Redux reducers and sagas. As used by react-boilerplate.
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
Dynamically load redux reducers and redux-saga sagas as needed, instead of loading them all upfront. This has some nice benefits, such as avoiding having to manage a big global list of reducers and sagas. It also allows more effective use of code-splitting. See motivation. As used by react-boilerplate.
The redux store needs to be configured to allow this library to work. The library exports a store enhancer that can be passed to the createStore function.
import { createStore } from "redux";
import { createInjectorsEnhancer } from "redux-injectors";
const store = createStore(
createReducer(),
initialState,
createInjectorsEnhancer({
createReducer,
runSaga,
})
)
Note the createInjectorsEnhancer function takes two options. createReducer should be a function that when called will return the root reducer. It's passed the injected reducers as an object of key-reducer pairs.
function createReducer(injectedReducers = {}) {
const rootReducer = combineReducers({
...injectedReducers,
// other non-injected reducers can go here...
});
return rootReducer
}
runSaga should usually be sagaMiddleware.run.
const runSaga = sagaMiddleware.run;
Redux DevTools
If you're using redux devtools, it's important to set shouldHotReload to false. This is because otherwise, redux devtools will re-dispatch previous actions when reducers are injected, causing unexpected behavior.
If using redux-toolkit:
const store = configureStore({
devTools: {
shouldHotReload: false
}
})
If not using redux-toolkit:
import { composeWithDevTools } from 'redux-devtools-extension';
const composeEnhancers = composeWithDevTools({
shouldHotReload: false
});
const store = createStore(reducer, composeEnhancers(
...
));
Unfortunately this causes a separate issue where the action history is cleared when a reducer is injected, but it's still strongly recommended to set shouldHotReload to false. There's an open issue in the redux-devtools repo about this.
Injecting your first reducer and saga
After setting up the store, you will be able to start injecting reducers and sagas.
Note: while the above usage should work in most cases, you might find your reducers/sagas aren't being injected in time to receive an action. This can happen, for example, if you dispatch an action inside a useLayoutEffect instead of a useEffect. In that case, useInjectReducer and useInjectSaga return boolean flags that are true once the reducers/sagas have finished injecting. You can check these before rendering children that depend on these reducers/sagas being injected.
There's a few reasons why you might not want to load all your reducers and sagas upfront:
You don't need all the reducers and sagas for every page. This library lets you only load the reducers/sagas that are needed for the page being viewed. This speeds up the page load time because you can take advantage of code-splitting. This is also good for performance after the page has loaded, because fewer reducers and sagas are running.
You don't want to have to manage a big list of reducers/sagas. This library lets components inject their own reducers/sagas, so you don't need to worry about adding reducers/sagas to a global list.
Đọc thêm về react-boilerplate/redux-injectors ở đâu?
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/react-boilerplate/redux-injectors là nguồn chính thức.
react-boilerplate/redux-injectors có phải mã nguồn mở không?
Có — react-boilerplate/redux-injectors phát hành theo license MIT, nghĩa là mã nguồn mở để đọc, fork và (tùy license) tái sử dụng. Mã: github.com/react-boilerplate/redux-injectors.
react-boilerplate/redux-injectors có website riêng không?
TopGit chưa ghi nhận URL trang chủ cho react-boilerplate/redux-injectors. Phần README ở tab phía trên thường có link demo, hoặc xem mô tả GitHub của repo.
react-boilerplate/redux-injectors dùng license gì?
react-boilerplate/redux-injectors phát hành theo license MIT. Nên mở file LICENSE trên GitHub để xác nhận — license metadata đôi khi lệch với thực tế dự án.
react-boilerplate/redux-injectors là gì?
react-boilerplate/redux-injectors (react-boilerplate/redux-injectors) là dự án JavaScript trên GitHub. Theo mô tả gốc: Asynchronous injectors for Redux reducers and sagas. As used by react-boilerplate.
Đọc đầy đủ README ở tab phía trên.
Chưa chắc redux-injectors có hợp với bạn?
Để ChatGPT, Claude hoặc Perplexity tìm hiểu giúp — bấm bên dưới và xem AI nói gì về redux-injectors.