useMappedState
在从 Ajax 响应接收更新时不会重新呈现组件下面是我的组件在运行。我已经记录了各个阶段的条目并附上了一个新的单一渲染的屏幕截图
您可以放心地假设 redux 部分对于 reducer 和操作可以正常工作,这可以从 mapState 中的 salesPerfData 控制台条目中看到,在响应扩展之前和之后从
import React, { useCallback, useState, useEffect, memo } from 'react';
import Grid from '@material-ui/core/Grid';
import Paper from '@material-ui/core/Paper';
import StackedChart from '../../../components/StackedChart/index';
import { useDispatch, useMappedState } from 'redux-react-hook';
import { Creators } from './actions';
const SalesPerformance = ( ) => {
const mapState = useCallback(
(state) => {
console.log('inside mapSate', state);
return { salesPerfData: state.salesPerfReducer.salesPerf }
},
[]
);
const { salesPerfData } = useMappedState(mapState);
console.log('after useMappedState', salesPerfData);
const dispatch = useDispatch();
useEffect(
() => {
dispatch(Creators.fetchSalesPerf({ filter: 'monthly', duration: 'last3' }))
},
[]
);
return (
<section>
<Paper className='mTB30'>
<Grid container>
<Grid item sm={12}>
<StackedChart config={salesPerfData} />
</Grid>
</Grid>
</Paper>
</section>
);
};
export default SalesPerformance;
沙盒链接在这里 - https://codesandbox.io/s/o490z3wwny