I got useState with a list of strings (currencies symbols like “USD”, “EUR” etc.)
JavaScript
x
2
1
const [symbols, setSymbols] = useState<string[]>()
2
And I need to display it into the select field, right now I’m using this:
JavaScript
1
18
18
1
const renderInputPanel = () => {
2
return (
3
<div className='input-panel'>
4
<form>
5
<select>
6
{symbols.map((symbol) => {
7
<option value={symbol}>symbol</option>
8
})}
9
</select>
10
</form>
11
</div>
12
)
13
}
14
15
return (<>
16
{renderInputPanel()}
17
</>)
18
It says the bug is in {symbols.map((symbol) =>...
, but I have no idea what to do with it. Full Error:
JavaScript
1
31
31
1
TS2322: Type 'void[]' is not assignable to type 'ReactNode'.
2
Type 'void[]' is not assignable to type 'ReactFragment'.
3
The types returned by '[Symbol.iterator]().next(...)' are incompatible between these types.
4
Type 'IteratorResult<void, any>' is not assignable to type 'IteratorResult<ReactNode, any>'.
5
Type 'IteratorYieldResult<void>' is not assignable to type 'IteratorResult<ReactNode, any>'.
6
Type 'IteratorYieldResult<void>' is not assignable to type 'IteratorYieldResult<ReactNode>'.
7
Type 'void' is not assignable to type 'ReactNode'.
8
24 | <form>
9
25 | <select>
10
> 26 | {symbols.map((symbol) => {
11
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
12
> 27 | <option value={symbol}>symbol</option>
13
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14
> 28 | })}
15
| ^^^^^^^^^^^^^^^^^^^^^^^^
16
29 | </select>
17
30 | </form>
18
31 | </div>
19
20
21
ERROR in src/converter/Converter.tsx:26:22
22
23
TS2532: Object is possibly 'undefined'.
24
24 | <form>
25
25 | <select>
26
> 26 | {symbols.map((symbol) => {
27
| ^^^^^^^
28
27 | <option value={symbol}>symbol</option>
29
28 | })}
30
29 | </select>
31
Advertisement
Answer
- add
return
before<option value={symbol}>symbol</option>
or
- delete
{}
wrapped outside<option value={symbol}>symbol</option>