'How to pass const value from one react js file to another?

I am a little new on react. How can I pass a variable with its value from one react js file to another?

File A.js:

const [value, setValue] = useState(35)  

File B.js:

import value from "./A.js"
console.log(value)


Solution 1:[1]

You have to export it either as a default or a regular export.

Try the following:

export const ...

or:

export default const ...

Solution 2:[2]

In file a.js // source file

Add this:

export const endpoint_val = 'value of endpoint';

Go to file b.js

import { endpoint_val } from './a.js'

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 DᴀʀᴛʜVᴀᴅᴇʀ
Solution 2 Jakub Kurdziel