我有以下内容:const col中传递的得分值未定义。我是React的新手。
const scores: React.FC<{styles: Styles;}> = ({ styles }) => {
const [score, setScore] = useState();
useEffect(() => {
async function retrieveData() {
const value = await AsyncStorage.getItem('score');
const data = JSON.parse(value);
setScore(data.First);
}
retrieveData();
});
const col: columnType[] = getScoreMetrics(status, score);
return (<BC styles={styles} col={col} />);
export default scores;
答案 0 :(得分:0)
尝试此代码
const scores: React.FC<{styles: Styles;}> = ({ styles }) => {
const [score, setScore] = useState();
useEffect(async() => {
async function retrieveData() {
const value = await AsyncStorage.getItem('score');
const data = await JSON.parse(value);
setScore(data.First);
}
retrieveData();
},[]);
const col: columnType[] = getScoreMetrics(status, score);
return (<BC styles={styles} col={col} />);
export default scores;