Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

Can't set state in a React functional component

$
0
0

I'm new to React and functional components and I wanted to create a simple app in which I have a Gallery component that I'm showing in the app, then I have a button that is supposed to set the state and pass it to the component, this is how it looks:

const App = () => {  const [images, setImages] = useState([]);  return (<ScrollView><View style={styles.body}><Button title="Press me" onPress={start} /><Gallery imgs={images}/> // Using the state here</View></ScrollView>  );};const start = () => {  // Create images array here  setImages(images); // [ReferenceError: Can't find variable: setImages]};export default App;

But I'm getting the following error: [ReferenceError: Can't find variable: setImages], but the setImages variable is defined in the same file so I don't understand what could be the problem.

Not sure if it matters but I'm using TypeScript.


Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>