I'm new to both javascript and react so there may be many things wrong here.
I have an interface LiquidityPosition
that I'm trying to display as components through my LiquidityList
component. I pass LiquidityList
an array of type LiquidityPosition[]
.
Here is my app.tsx:
import React, { useState } from 'react';
import LiquidityList from './components/LiquidityList';
import { LiquidityPosition } from './components/Liquidity'
function App() {
let positions = [
{
time: new Date(2018, 11, 24, 10, 33, 30, 0),
sizeA: 2,
sizeB: 1
}
]
return (
<>
<LiquidityList {...positions}/>
</>
)
}
export default App;
LiquidityList.tsx:
import React from 'react'
import { LiquidityPosition } from './Liquidity';
import Liquidity from './Liquidity';
export default function LiquidityList(posList: LiquidityPosition[]) {
return (
<>
{
posList.map(pos => <Liquidity {...pos}/>)
}
</>
)
}
For some reason here, posList is not an array, since it doesn't have a .map
method? The error message:
TypeError: posList.map is not a function