【发布时间】:2019-11-22 10:00:26
【问题描述】:
我正在尝试使用 redux 值来使用 useState 设置 React 组件的初始状态。当我尝试设置 setIsStar 的状态时,它说 currentChannelName 为空。我怎样才能避免这种情况?或者有没有其他方法
const currentChannel = useSelector(state => state.channel.currentChannel);
const currentChannelName = currentChannel.name;
const [isStar, setIsStar] = useState({
[currentChannelName]: true
});
【问题讨论】:
标签: reactjs redux react-hooks