Describe react-redux
Use the provider component to share a store
Use connect to mapStateToProps and mapDispatchToProps
import React from 'react';
import ReactDOM from 'react-dom';
import {Provider} from 'react-redux';
import {createStore} from 'redux';
import rootReducer from './reducers';
const store = createStore(rootReducer);
ReactDOM.render(
<Provider store={store}>
<App />
</Provider>,
document.getElementById('root')
);
import React from 'react';
import {connect} from 'react-redux';
const BoldName = ({name}) => (
<strong>{name}</strong>
);
const mapStateToProps = state => (
{ name: state.name }
);
export default
connect(mapStateToProps, null)(BoldName);
import React from 'react';
import {connect} from 'react-redux';
const DelName = ({delName}) => (
<button type="button"
onClick={delName}>DELETE</button>
);
const mapDispatchToProps = (
dispatch, ownProps
) => (
{
delName: () => (dispatch({
type: "DEL_NAME"
}))
}
);
export default
connect(null, mapDispatchToProps)(DelName);
import React from 'react';
import BoldName from './BoldName';
import DelName from './DelName';
const App = () => (
<div>
<BoldName />
<DelName />
</div>
);