Why am I able to do this:
export const state = {};
but I can't do this:
const state = {}
export state; // 'Declaration or statement expected' error
Why am I able to do this:
export const state = {};
but I can't do this:
const state = {}
export state; // 'Declaration or statement expected' error
So you have 2ways to use export: This one you've already done:
export const state = /*whatever you want*/
And this one:
const state = /*whatever you want*/
export { state };
And then you may use it with:
import { state } from './otherFileName'
Quote from documentation:
Syntax
export { name1, name2, …, nameN }; export { variable1 as name1, variable2 as name2, …, nameN }; export let name1, name2, …, nameN; // also var, function export let name1 = …, name2 = …, …, nameN; // also var, const