или не умею передавать данные между родителем и дочерним или не знаю useConext
index.js:
import React, {createContext} from 'react';
import App from './App';
import ReactDOM from 'react-dom';
export const Context = createContext(null)
ReactDOM.render(
<Context.Provider value={{
device: [
{id:1,name:'hello'},
],
}}>
<App />
</Context.Provider>,
document.getElementById('root')
);
App.js
import React, {useContext, useEffect, useState} from 'react';
import './App.css';
import Shop from './components/Shop';
function App() {
return (
<Shop/>
);
}
export default App;
Shop.js:
import React, {useContext, useEffect} from 'react';
import {Context} from "../index";
import Phone from './Phone';
function Shop() {
const {device} = useContext(Context)
return (
<div>
{device.devices.map(device =>
<Phone key={device.id} device={device}/>
)}
</div>
);
}
export default Shop;
Phone.js:
import React from 'react';
function Phone({device}) {
return (
<div>
<h1>{device.name}</h1>
</div>
);
}
export default Phone;
в чем проблема?