I'm trying to map through an array loaded from redux store, map through and pass down the information to a new component.
This is what the object from store looks like:
tasks: {
results: [
id: number,
name: string,
]
}
The component where the informartion will be passed down to is a simple table row:
interface TaskProps {id: number, name: string}
const TaskTableRow: FC<TaskProps> = ({id, name}) => {
return(
<tr>
<td>{id}</td>
<td>{name}</td>
</tr>
)
}
export default TaskTableRow
My table component looks similiar to this:
interface TaskProps {id: number, name: string}
const TaskTable = () => {
...
const tasks = useSelector((state: TasksState) => state.tasks)
...
const content = tasks.results ?
tasks.results.map<TaskProps>(
item => <TaskTableRow id={item.id} name={item.name} />
) : []
return (
...
<tbody>
{ content }
</tbody>
...
);
}
export default TaskTable
My idea was to access the data via item.something, but right now the complete <TaskTableRow />-Element is marked as error with the following information TS2739: Type 'ReactElement<any, any>' is missing the following properties from type 'TaskProps': id, name, slug, status.
What am I missing here, or is the whole approach wrong?
TaskPropshere?tasks.results.map<TaskProps>. The argument here is a return type of the map, not the argument type