While learning ReactJS over this summer and one of the biggest mistakes I made was using a third-party library to outline my layouts, just because I didn’t want to go through all the hassle of designing a whole website.
I reviewed quite a lot of possible projects that I could try while in the process of learning ReactJS and also stumbled upon this frightful post about puppy dieing when someone builds a To-do list applications. It’s whatever at this point, if building a To-do application teaches me quite a lot of things about ReactJS, why not?!
I think, the biggest problem for me was that I was trying to read a .json file without completely uploading it to a server (fully client-sided). 1
While playing with antdUpload component, it was clear enough until importing a file and initializing the file but never actually clearly mentioned about originFileObj. Let’s take any of those components as an example and look through their sample code.
I then started searching for answers about why info.file wasn’t returning an actual file handle for me to read through with FileReader() but worked flawlessly as info.file was missing originFileObj property that actually is the actual file object handle.
We have two options to access our actual file object, we could use either info.file.originFileObj or info.fileList[..].originFileObj. Below is the code I used in my To-do tasks application.
Exporting files as JSON is pretty easy as well after reading some documentations.
Pretty funny problem but as long as the solution is quite fun to find, we are good!
The reason behind me wanting to read a JSON file completely client side was because of the project I was working on. Trail is a task completion web-application developed in ReactJS, I wanted to make it as simple as possible as there was no plans to create a way to backup the data. ↩