Answer the question
In order to leave comments, you need to log in
Why does Typescript swear at props?
The code of the file from which the props are thrown:
import React, { ReactNode } from 'react'
import s from './Fishes.module.css'
import clownfish from '../../image/clownfish.svg';
import fish from '../../image/fish.svg';
import fish1 from '../../image/fish1.svg';
import fish2 from '../../image/fish2.svg';
import fish3 from '../../image/fish3.svg';
import fish4 from '../../image/fish4.svg';
import Fish from './Fish/Fish';
const Fishes: React.FC = () => {
let array: { name: ReactNode, random: number }[] = [
{
name: clownfish,
random: Math.random() * (80 - 20) + 20
},
{
name: fish,
random: Math.random() * (80 - 20) + 20
},
{
name: fish1,
random: Math.random() * (80 - 20) + 20
},
{
name: fish2,
random: Math.random() * (80 - 20) + 20
},
{
name: fish3,
random: Math.random() * (80 - 20) + 20
},
{
name: fish4,
random: Math.random() * (80 - 20) + 20
},
];
console.log(array);
return (
<div className={s.area}>
{array.map(el => <Fish imgName={el.name} random={el.random} />)}
</div>
)
}
export default Fishes;
import React from 'react'
import s from './Fish.module.css'
const Fish: React.FC = (props: any) => {
return (
<div className={s.area}>
<img src={props.imgName} className={s.imgName} alt={props.imgName} />
</div>
)
}
export default Fish;
Answer the question
In order to leave comments, you need to log in
It is necessary to properly type Fish, then everything will be beautiful.
interface FishProps {
imgName: string;
random: number;
}
const Fish: React.FC<FishProps> = (props) => {
...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question