


Программирование
+2Ошибка с функцией при заходе на localhost React
Делал по гайду из ютуба проект на реакте и блогер вывел функцию в другой файл. После этого ошибка:
1
Functions are not valid as a React child. This may happen if you return a Component instead of <Component /> from render. Or maybe you meant to call this function rather than return it
Код, в котором вызывается функция:
1234567891011121314151617181920212223242526272829
import { useState } from 'react';
import {cars} from './cars.data';
import Car_item_fun from './car_item/cars_item';
function Home() {
const [count, setCount] = useState(0)
return (
<>
<div>
<h1>Cars Catalog</h1>
{/* <img src="https://honda_civic.jpg" width="-1" height="-1" alt = "false|false"/> */}
{cars.length ? cars.map(
car => <><Car_item_fun key = {car.id} car = {car} /></>
)
: <p>There no cars</p>
}
</div>
</>
)
}
export default Home
Код, в котором прописана функция:
12345678910111213141516171819202122
function Car_item_fun ({ car }){
return(
car => (
<div className = 'car_card' key = {car.id}>
<div className = 'honda_civic_img' style = {{
backgroundImag: `url(${car.img_link})`,
}}></div>
<h3>{car.name}</h3>
<h2><b>{new Intl.NumberFormat(
'ru-Ru', {style: 'currency', currency: 'USD'}
).format(car.price)}n</b></h2>
<button style = {{
border: 'none',
}}>Read more</button>
</div>
)
)
}
export default Car_item_fun
По дате
По рейтингу
Во 2 блоке скорее всего ошибка. Зачем обернул все в функцию? В return разметку ставь и все