我是 React 的初学者,我对 react-grid-layout 有疑问,事实上,我在 reducer 中创建了一个动作来重置我的卡片在网格中的位置。存储在“props”中的参数随我的意愿改变,但视觉渲染没有考虑到新参数,这是我的代码:
const DashboardGrid = (props) => {
let [content, setContent] = useState();
useEffect(() => {
setContent(CreateContent(props));
}, [props.newGrid])
function CreateContent(props) {
let dash = props.newGrid
content = dash.map((_c, _i) => {
if (dash[_i].isVisible === true) {
return (
<div className='case' key={_i} cti={_i} data-grid={dash[_i].dataGrid}>
<Card id={_i} />
</div>
)
}
})
return content
}
function restore() {
props.restoreGrid()
}
CreateContent(props)
return (
<GridLayout className="layout" cols={props.cols} rowHeight={props.rowHeight} width={props.width}>
<div key="title" data-grid={props.dashboards.dataGridTitle} className="dashTitle">{props.dashboards.title}</div>
<div onClick={restore}>
<Icon type="undo" />
Restaurer la grille
</div>
{content}
</GridLayout>
)
}
const mapStateToProps = state => {
return {
newGrid: state.async.dashboards[0].dashboard,
dashboards: state.async.dashboards[0]
}
};
const mapDispatchToProps = dispatch => {
return {
restoreGrid: () => dispatch(cardAction.restoreGrid()),
}
};
export default connect(mapStateToProps, mapDispatchToProps)(DashboardGrid)
我的减速器在我的道具中向我发送了良好的坐标,但我的网格的组件没有改变。请告诉我,或者我错了,或者是否有可能强制计算组件。