D
D
depstor2020-04-16 17:57:24
React
depstor, 2020-04-16 17:57:24

How to display data in React JS page?

import React, { useState } from 'react';
import { Form, Input, Button, Card } from 'antd';
import style from '../../index.scss';

const App = () => {

const [todos, setTodos] = useState('');



const onFinish = values => {
  const newTodoItem = {title: values.todoTitle, complete: false}
  const newTodos = [...todos, newTodoItem]
  setTodos(newTodos)
  console.log(newTodoItem)
}

  return (
      <>
      <h1 className={style.title}>To-Do</h1>
      <div>
    <Form
      name="basic"
      onFinish={onFinish}
      style={{ width: 200 }}
    >
      <Form.Item
        name="todoTitle"
      >
        <Input />
      </Form.Item>

      <Form.Item>
        <Button type="primary" htmlType="submit">
          Add
        </Button>
      </Form.Item>
    </Form>
    </div>
    <ul><li>oooo</li></ul>
    </>
  );
};

export default App;
Добрый день, подскажите как вывести данные на страницу в функции onFinish я получаю новые todo items  но как их отрендарить я не понимаю, может кто объяснит и подскажет что почитать ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aleks0123456789, 2020-04-16
@depstor

https://www.robinwieruch.de/react-hooks-fetch-data
https://codesandbox.io/s/jvvkoo8pq3
https://ru.reactjs.org/docs/hooks-faq.html#how-can. ..

<ul>{
todos.map(todo=>(
<li key={todo.id}>{todo}</li>
))
}</ul>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question