卡在这个问题上,可能是一些逻辑错误,但我自己找不到 有任何更正吗? (问题-'找不到变量:方向'。使用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);
答案 0 :(得分:0)
变量direction
仅在函数nextGuessHandler
内定义,因此在尝试在函数外部使用时会失败