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)
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)
You have to export it either as a default or a regular export.
Try the following:
export const ...
or:
export default const ...
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'