正在添加getDerivedStateFromProps作为传统componentWillReceiveProps的更安全的替代方案.
这就是16.3文档所说的.这个生命周期还有什么更多还是仅仅是名称变更?
我见过博客,指出所有HOC都可以转换为渲染道具。
我的守则中有此HOC。我想知道是否可以将其转换为渲染道具。
这是一个连接的HOC。
import React from 'react';
import { compose } from 'redux';
import { connect } from 'react-redux';
import { modes } from '../../../modes';
const Wrapper = Component => (props) => {
const { mode, ...rest } = props;
if (mode === modes.VIEW) {
return (<Component
{...rest}
disabled
/>);
}
return (<Component
{...rest}
/>);
};
const mapStateToProps = state => ({
mode: state.mode,
});
const composedHOC = compose(
connect(mapStateToProps, null),
Wrapper
);
export default composedHOC
;
Run Code Online (Sandbox Code Playgroud) 我知道redux中的调度操作是同步的.当我从第1行的反应组件向redux发送操作时,我可以100%确定反应组件中的第2行是否具有更新的redux状态?我正在通过调度getGameDataSuccess(data)动作设置游戏数据.我可以100%确定在下一行中新的道具会流下来吗?现在当我console.log(this.props.lostLetters.gameData),我看到新的游戏数据.但我能100%确定这种情况总是如此吗?
getLostLettersGame(this.props.gameCenter.selectedGame.gameId)
.then((data) => {
this.props.dispatch(LostLettersActions.getGameDataSuccess(data));
console.log(this.props.lostLetters.gameData);
this.generateGame();
})
Run Code Online (Sandbox Code Playgroud)