Created
August 24, 2021 08:40
-
-
Save gokhancerk/a332143334fbd33899354eee42b4113f to your computer and use it in GitHub Desktop.
redux cheetsheet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { connect } from "react-redux"; | |
function App(props){ | |
return ( | |
<div>App</div> | |
); | |
} | |
// reducer içindeki state'e erişir, state'in içindeki değerlerden hangisini istersek onu return eder | |
// redux'da state props'lara yazdırılır | |
const mapStateProps = (state) => { | |
return { | |
liste: state.liste | |
}; | |
}; | |
export default connect(mapStateProps)(App); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// create store - import { createStore } from "redux"; | |
// create reducer and pass to the createStore | |
// wrapping by Provider - import { Provider } from "react-redux"; | |
import React from "react"; | |
import ReactDOM from "react-dom"; | |
import { createStore } from "redux"; | |
import { reducer } from "./reducers"; | |
import { Provider } from "react-redux"; | |
const store = createStore(reducer); | |
ReactDOM.render( | |
<Provider store={store}> | |
<App /> | |
</Provider>, | |
document.getElementById("root"); | |
); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const INITIAL_STATE = { | |
liste: [ | |
{ id: 1, baslik: "Alisveris Yap", tamamlandi: false }, | |
{ id: 2, baslik: "Fatura ode", tamamlandi: true } | |
] | |
}; | |
export const reducer = (state = INITIAL_STATE, action) => { | |
return state; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment