Search code examples
react-nativeapipostreact-native-flatlist

How to post data in flatlist after pressing button


I have two Text inputs and i want to post data in flatlist after i press a button. How can i make it? And does flatlist update it at the same time? Also how to sync it on a server to show all users

<TextInput style={{ backgroundColor: '#ededed', height: 60 }} value={'name'} />
<TextInput style={{ backgroundColor: '#ededed', height: 60 }} value={'description'} />

Solution

  • You can pass a state as data to the Flatlist. And then update that state on button press. To sync it to the server, you can fire a post request(with the updated state) on the same button press.