Skip to content
Advertisement

Split up functionalities across project in React?

Alright so I’m new to React, and have made an application which gets some data from an API and stores it into a table. It worked, but most of the code was in a single file which irritated me a lot. Now I’m trying to split it across multiple files, but without much luck as of yet.

I followed an answer which said I could just create a APIManager and use the following code:

JavaScript

However this gives me a TypeError: Object(...) is not a function. I tried it with a plain function, export function, and this, but nothing works. Should I make a component out of it? This is where the code gets called:

JavaScript

Advertisement

Answer

Alright, with the help of @digitalbreed I managed to fix it! I changed

JavaScript

to

JavaScript

and changed my reference to the code from

JavaScript

to

JavaScript

with

JavaScript

And it works fine now. Thanks for the help, digitalbreed!

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement