Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/471.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 我如何检查onclick道具是否比redux状态更快 const dispatch=usedpatch(); const{emotionCard}=useSelector((state)=>state.selectedReducer); const[check,setCheck]=useState(false); const selectId=props.id const emotionId=emotionCard.selectId //恒定情绪 常量handleClick=(e)=>{ 分派((selectEmotionAction({selectId})); console.log(selectId,emotionId) } 如果(道具id==“欢乐”){ 返回( 1. ) }否则如果(props.id==“种类”){ 返回( 0 ) }否则如果(props.id==“谢谢”){ 返回( 2. ) }否则如果(props.id==“不舒服”){ 返回( 3. ) }_Javascript_Reactjs_Redux_Use State - Fatal编程技术网

Javascript 我如何检查onclick道具是否比redux状态更快 const dispatch=usedpatch(); const{emotionCard}=useSelector((state)=>state.selectedReducer); const[check,setCheck]=useState(false); const selectId=props.id const emotionId=emotionCard.selectId //恒定情绪 常量handleClick=(e)=>{ 分派((selectEmotionAction({selectId})); console.log(selectId,emotionId) } 如果(道具id==“欢乐”){ 返回( 1. ) }否则如果(props.id==“种类”){ 返回( 0 ) }否则如果(props.id==“谢谢”){ 返回( 2. ) }否则如果(props.id==“不舒服”){ 返回( 3. ) }

Javascript 我如何检查onclick道具是否比redux状态更快 const dispatch=usedpatch(); const{emotionCard}=useSelector((state)=>state.selectedReducer); const[check,setCheck]=useState(false); const selectId=props.id const emotionId=emotionCard.selectId //恒定情绪 常量handleClick=(e)=>{ 分派((selectEmotionAction({selectId})); console.log(selectId,emotionId) } 如果(道具id==“欢乐”){ 返回( 1. ) }否则如果(props.id==“种类”){ 返回( 0 ) }否则如果(props.id==“谢谢”){ 返回( 2. ) }否则如果(props.id==“不舒服”){ 返回( 3. ) },javascript,reactjs,redux,use-state,Javascript,Reactjs,Redux,Use State,} 如果我的selectId==emotionId为true和false,我想在handleclick中获取函数setcheck切换! 但我调试它,在handleclick中selectId比emotionId快 因此,如果我像这样单击kind=>(kind,joy),我的控制台会像(joy,undefined)=>一样。如何解决此问题??:(您必须将情感卡存储在本地状态,如下所示: const dispatch = useDispatch(); const { emotionCard } =

}

如果我的selectId==emotionId为true和false,我想在handleclick中获取函数setcheck切换! 但我调试它,在handleclick中selectId比emotionId快


因此,如果我像这样单击kind=>(kind,joy),我的控制台会像(joy,undefined)=>一样。如何解决此问题??:(

您必须将情感卡存储在本地状态,如下所示:

const dispatch = useDispatch();
const { emotionCard } = useSelector((state) => state.selectedReducer);
const [check, setCheck] = useState(false);

const selectId = props.id
const emotionId = emotionCard.selectId
// const emotion

const handleClick = (e) => {
    dispatch((selectEmotionAction({selectId})));
    console.log(selectId, emotionId)
}

if (props.id === "joy"){
    return (
        <SelectBox onClick={handleClick} check={check}>
            <SelectBox_Left>
                <img src={check ? joyWhite : joyPink}/>
                <SelectText check={check}>1</SelectText>
            </SelectBox_Left>
            <SelectBox_Right_1>
                <img src={fundingImg1}/>
            </SelectBox_Right_1>
        </SelectBox>
    )
} else if (props.id === "kind") {
    return (
        <SelectBox onClick={handleClick} check={check}>
            <SelectBox_Left>
                <img src={check ? kindWhite : kindPink}/>
                <SelectText check={check}>0</SelectText>
            </SelectBox_Left>
            <SelectBox_Right_2>
                <img src={fundingImg2}/>
            </SelectBox_Right_2>
        </SelectBox>
    )
} else if (props.id === "thanks") {
    return (
        <SelectBox onClick={handleClick} check={check}>
            <SelectBox_Left>
                <img src={check ? thanksWhite : thanksPink}/>
                <SelectText check={check}>2</SelectText>
            </SelectBox_Left>
            <SelectBox_Right_3>
                <img src={fundingImg3}/>
            </SelectBox_Right_3>
        </SelectBox>
    )
} else if (props.id === "uncomfortable") {
    return (
        <SelectBox onClick={handleClick} check={check}>
            <SelectBox_Left>
                <img src={check ? unWhite : unPink}/>
                <SelectText check={check}>3</SelectText>
            </SelectBox_Left>
            <SelectBox_Right_4>
                <img src={fundingImg4}/>
            </SelectBox_Right_4>
        </SelectBox>
    )
}

您是否在数组
情感卡
中有属性
selectId
 const { emotionCard } = useSelector((state) => state.selectedReducer)
 const [emotionId, setEmotionId] = useState(emotionCard)

 useEffect(() => {
    if (emotionCard) setEmotionId(emotionCard.selectId)
 },[emotionCard])