简体   繁体   English

function 部分不运行

[英]Part of the function doesnt run

I have this function when a button is clicked but for some reason it stops before the if statement.单击按钮时我有这个 function 但由于某种原因它在 if 语句之前停止。

Here is the javascript:这是 javascript:


    const nextStep = (e) => {

        e.preventDefault();
        console.log('click')
        let value = e.target.value;
        console.log(value);
        props.setAge(value);
        console.log('set props');

        if(value === 'Yes' && navBarData.isMedicare !== true){

            console.log('went into true')
            //if yes -> continue to medicare routes -> Leave default navbar data
            props.updateMedicareNavBarData();
            console.log('updated medicare prop')
            navigate('/enrolled')
            console.log('nav')

        }  else if (value === 'No' && navBarData.isHealth !== true) {
            //if no -> health care routes -> use health navvar data
            console.log('went into no')
            props.updateHealthNavBarData();
             navigate('/coverage-time')
        }

    }

here is the button:这是按钮:

<div className=" leading-5 buttonBlock">
                                {buttons.map((button) => (
                                    <button
                                        className="chooseButton border border-blue-500 rounded text-blue-500 hover:bg-blue-500 hover:text-white hover:shadow-lg hover:shadow-blue-500/50 transition duration-200 font-bold"
                                        key={button.key}
                                        id={button.id}
                                        value={button.value}
                                        onClick={nextStep}
                                    >
                                        {button.title}
                                    </button>
                                ))}
                            </div>

and lastly here is my console log:最后是我的控制台日志:

click - Age.jsx:20 
Yes - Age.jsx:22 
set props - 

as you can i see i have console logs in the if statement but that doesnt happen, any idea why this is happending?如您所见,我在 if 语句中有控制台日志,但没有发生,知道为什么会发生这种情况吗?

Most probably, both the if statement and else if statement are false.最有可能的是, if语句和else if语句都是错误的。 Make an else statement printing something to the console.做一个else语句,在控制台上打印一些东西。 If it does print, then both conditions above are false- if it doesn't print for some reason (which is unlikely), then there may be another issue.如果它确实打印了,那么上面的两个条件都是错误的——如果它由于某种原因没有打印(这不太可能),那么可能还有另一个问题。 We can cross that bridge if we come to it, though.不过,如果我们来到它,我们可以越过那座桥。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM