28 Mayıs 2019 Salı

React Redux Store

Giriş
Açıklaması şöyle.
React components can accept properties as well as manage their own state. Redux provides a global app state that any component can link into.
Nerede Faydalı
Açıklaması şöyle.
Redux gives you a global state. This can be helpful when you have deeply nested components that need to share the same state. Rather than passing unrelated properties down the component tree, you can simply access the Redux store.
Store Yaratma
createStore() metodu ile store oluşturulur. İlk parametre Reducer nesnesidir.

Reducer
Reducer yeni state nesnesi döner. Açıklaması şöyle.
The next thing you’ll need is a reducer to tell Redux how an action should affect the data store. Reducers should be pure functions that return a new state object rather than mutating the original state.
...
The reducer takes the current state object. If the state is undefined, which will be true during initialization, then you will want to provide a default, or initial, state. You then need to look at the type of the action to determine what you should do with the data.
Provider
React ile Redux'i birleştirmek için Provider sınıfı kullanılır. Provider React'ın ana bileşenini sarmalar.
Açıklaması şöyle. Böylece react'diğer bileşenleri Store nesnesine erişebilir.
The Provider component has access to the store and passes it along to child components using context. A component, later on, can access the store, even if it is deeply nested in the React tree.
Açıklaması şöyle.
It allows us to pass our store which contains the state into the React component. You can pass it the same way you pass the properties in the React component.


Hiç yorum yok:

Yorum Gönder