这个问题的根本原因是 Ant Design 的 Step 组件没有正确的状态管理机制。为了解决这个问题,请按照以下方式添加状态管理:
在父组件中添加一个 state,用于控制 Step 的当前状态。例如:
class ParentComponent extends React.Component {
state = {
currentStep: 0,
}
handleNextStep = () => {
const { currentStep } = this.state
this.setState({
currentStep: currentStep + 1,
})
}
render() {
const { currentStep } = this.state
return (
)
}
}
在子组件中通过 props 接收父组件传递下来的函数,用于触发 Step 的状态更新。例如:
function ChildComponent({ onNextStep }) {
return (
)
}
这样,当子组件中的按钮被点击时,父组件的状态将得到更新并通过 Step 的 current 属性传递下去,从而实现状态的同步更新。