找不到变量:方向

时间:2019-10-20 21:57:06

标签: reactjs react-native

卡在这个问题上,可能是一些逻辑错误,但我自己找不到 有任何更正吗? (问题-'找不到变量:方向'。使用react。

const GameScreen = props => {
const [currentGuess, setCurrentGuess] = useState(
    generateRandomBetween(1, 100, props.userChoice)
);
    const currentLow = useRef(1);
    const currentHigh = useRef(100);

    const nextGuessHandler = direction => {
        if ((direction === 'lower' && currentGuess < props.userChoice) || (direction === 'greater' && currentGuess > props.userChoice))
        Alert.alert('Don\'t lie!', 'You know that this is wrong...', [{text: 'Sorry!', style: 'cancel'}
    ]);
    return;
    }
    if (direction === 'lower') {
        currentHigh.current = currentGuess;
    } else {
        currentLow.current = currentGuess;
    }
    const nextNumber = generateRandomBetween(currentLow.current, currentHigh.current, currentGuess);
    setCurrentGuess(nextNumber);

1 个答案:

答案 0 :(得分:0)

变量direction仅在函数nextGuessHandler内定义,因此在尝试在函数外部使用时会失败