0

Задачка попроще, но тем не менее для меня непонятная, ибо везде разные ответы и мне ничего не понятно(

Есть два файла app.js и table.js

В первом файле у меня есть массив в константе

   const Products = 
  {
    name: "one",
    id: "1"
  }

и функция

function travell(Products) {
  return Products.name;
}

Во втором файле у меня функция, куда надо передать значения функции из первого файла. Чтобы я не делала пишет, что не видит значений функции.

function Tables (Products) {
    return (
        <table>
            <tr>
                <td>
               
                </td>
            </tr>
        </table>
    )
}

Полный код 1ого и 2ого файла, кому это будет необходимо

import React from 'react';
import './App.css';
import Tables from './Tables/Tables';

function travell(Products) {
  return Products.name;
}

const Products = 
  {
    name: "one",
    id: "1"
  }


function App() {
  
  return (
    <div>
      <h1 style={{textAlign: "center"}}>Product</h1>
      
      <Tables />
    </div>
  );
}

export default App;

Второй

import React from 'react';
import '../App.js';
import App from '../App';

function Tables (Products) {
    return (
        <table>
            <tr>
                <td>
               
                </td>
            </tr>
        </table>
    )
}
export default Tables

1 ответ 1

3

Вы не передаете пропсы в дочерний компонент Tables

function App() {
    return (
        <div>
            <h1 style={{textAlign: "center"}}>Product</h1>
            <Tables Products={Products}/>
        </div>
    );
}

function Tables (props) {
    // >> props.Products
    return (
        <table>
            <tr>
                <td>
                </td>
            </tr>
        </table>
    )
}

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.