Skip to content
Advertisement

React Constants inside a Function

I need help to export the constants. I am getting different errors when i try to search for this on google or other related topics at stackoverflow.

This is my Printer.jsx

JavaScript

I need to add the const connect to the App.js so that if the App is starting the connection is also starting. The second is that i need to add the const print to ReactB.js-file so if content of ReactB.js-page is loading the print-request should be send.

Thanks for your help! Stuck at this since 5 hours and dont know how to deal with this problems.

Advertisement

Answer

It seems your main issue stems around how to export constants. I recommend checking out MDN for more info: https://developer.mozilla.org/en-US/docs/web/javascript/reference/statements/export

Below is an excerpt on named exports that is relevant to your scenario.

JavaScript

So for your example, it would just be a matter of adding declaring the const with export const connect = value; or adding export { connect }; after it is declared.

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