[KDT]FCFE-9週1日Reduxビュー(ReactContextが存在し、Reduxが必要な理由から)
5379 ワード
Redux
なぜReact Contextが必要なのですか?
React Contextのみを使用する場合の潜在的な欠点
return (
<AuthContextProvider>
<ThemeContextProvider>
<UIInteractionContextProvider>
<MultiStepFromContextProvider>
<UserRegistration />
</MultiStepFromContextProvider>
</UIInteractionContextProvider>
</ThemeContextProvider>
</AuthContextProvider>
)
Reduxの構造
1つのプロジェクトに1つのリポジトリ(中央データ・リポジトリ)のみがプロジェクト全体に使用されます.
中央リポジトリは、特定のコンポーネント(設定済み)をサブスクリプションし、中央データ・リポジトリのステータスが変更されたサブスクリプション・コンポーネントに通知します.
storeでデータを直接操作しません.
アセンブリは減速機に動作を伝達します.reduceは、受信した操作を確認し、対応する操作を使用して中央リポジトリのデータを変更します.
Reducer Function
const redux = require('redux');
// state에 초기값 설정
const couterReducer = (state = {counter:0}, action)=>{
return {
counter: state.counter +1
};
};
const store = redux.createStore(counterReducer);
const couterSubscriber =() =>{
// 스토에 안에 최신 업데이트된 data를 가져올수 있는 함수
const latestState = store.getState();
console.log(latestState);
}
// data를 가져간 함수를 구독하여 data가 최신화 되면 업데이트 해줌.
store.subscribe(counterSubscriber);
Reference
この問題について([KDT]FCFE-9週1日Reduxビュー(ReactContextが存在し、Reduxが必要な理由から)), 我々は、より多くの情報をここで見つけました https://velog.io/@leedocs/KDTFCFE-9주1일-Redux-파보기-ReactContext가-있는데-Redux가-필요한-이유부터テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol