Raphael Heard
Raphael Heard

Reputation: 99

How to read and write a to a local file in Reactjs

I have a file call data.txt in the root of my project same directory as App.js and package.json. I want to open the file data.txt read though the lines, change somethings, and save it back. This is done in a component. Is this possible in Reactjs? if it is can you kindly give me an example i can follow or links to where i can see an example.

Upvotes: 0

Views: 598

Answers (1)

Christian Fritz
Christian Fritz

Reputation: 21364

React (typically) runs in the browser, but the file you are talking about lives on the server. So no, not just like that. You'd need to create some sort of API to send the data to the browser and back.

Upvotes: 1

Related Questions