为了让Redux Store更新Redux-to-library的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 { connect } from 'react-redux';
const MyComponent = ({ data }) => {
// 使用Redux Store中的数据进行渲染
return <div>{data}</div>;
};
const mapStateToProps = (state) => {
return {
data: state.data // 将Redux Store中的data状态映射到组件的props上
};
};
export default connect(mapStateToProps)(MyComponent);
领取专属 10元无门槛券
手把手带您无忧上云