Simon Long
Simon Long

Reputation: 1440

Flow type for useMemo hook

Simple question.

I've declared a string array using useMemo and I'm struggling to get the correct flow type for it.

I have the following :

const fruits: () => Array<string> = useMemo(() => ['Apples', 'Oranges', 'Bananas'],[]);

and get the following flow error

Cannot assign useMemo(...) to fruits because array literal [1] is incompatible with function type [2].

Upvotes: 1

Views: 524

Answers (1)

Simon Long
Simon Long

Reputation: 1440

Sorry, the following works. It's just as simple as using :

const fruits: Array<string> = useMemo(() => ['Apples', 'Oranges', 'Bananas']);

Upvotes: 1

Related Questions