Scenario: I was using Formik in React. There was a need to convert formik values to FormData to send to API as post.
This is how it was done.
// A sample object
let values = { name : 'Kiran', location: 'Sedona' };
let data = new FormData();
for (let key in values) {
data.append(key, values[key]);
}
console.log(data);
Leave a comment