Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get data from React native FormData Object

I am working on a react native project. I am using FormData to upload my files and input text.

But in form validation, I need to get the Value from the FormData object. I tried formData.get('mykey') but it gives me an error that gets is not a function. Can anyone please tell me how can I do that?

thanks.

like image 992
Pankaj Agrawal Avatar asked Sep 01 '26 12:09

Pankaj Agrawal


1 Answers

You can use FormData#getParts:

const field = data.getParts().find(item => item.fieldName === 'key'));
if (field) {
  const value = field.string;
}

See relevant React Native source code for FormData.

like image 170
jevakallio Avatar answered Sep 03 '26 04:09

jevakallio



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!