【发布时间】:2021-07-26 08:27:31
【问题描述】:
对不起。我是新来的反应原生和反应。
我刚刚遇到setCount is not a function. (In 'setCount(1)','setCount' is undefined) 错误。
如何在 AComponent 中使用setCount 方法?
import React, {useState} from 'react';
import {
Text,
} from 'react-native';
const AComponent = ({count, callback}) => {
callback(1);
return <Text>{count}</Text>;
};
const App = () => {
const [count, setCount] = useState(0);
return <AComponent count={count} callback={setCount} />;
};
const styles = StyleSheet.create({
container: {},
});
export default App;
【问题讨论】:
标签: react-native callback use-state