So, I'm the first to admit I really struggle with React. I'm fine with JS and JQuery and have even completed many, many React tutorials. But when it comes to converting an existing JavaScript script into a React component, I'm completely stumped.
Right now I have a JavaScript script that is moderately complex.
It reads user data from and object in an external .js file.
Based off that data (or combinations of that data) the script writes elements to the DOM or fires off a modal.
So, for example, a simple if statement might be:
if (userdata.userage > 50 && userdata.userjob.userincome > 100000){
$(".js-modal-body").load(info[key].content);
$('#alertModal').foundation('open');
Cookies.set(modalName, '1', { expires: 7 })
}
And so on.
I won't paste the whole code in here, but basically it consists of:
- An import, brining in the userData object from a user.js file.
- A stand-alone helper function that returns the user's age based of their inputted date-of-birth and today's date.
- A series of if statements like the one above. Some if statements fire off Modals, some write new card elements to the DOM. Some also create cookies.
My question is where do I start when want to convert this to react?
Top comments (0)