'why I am getting undefined when passing an array into a usestate argument (react js)

code : const [Proposals, setProposals] = useState(sequenceProposals); sequenceProposals is an imported array from other file. console.log(sequenceProposals) gives me array having 40 objects console.log(Proposals) gives my undefined. -> why???



Solution 1:[1]

Please make sure you are exporting the data in other file. e.g.

export const sequenceProposals = [{}, {}, ...]

And the also check whether you are destructuring that data while importing. e.g.

import {sequenceProposals} from '<file_location>/your_file'

This destructured data can be used directly while setting up the state.

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 dev_sanketsr