addCategory.js 922 B

123456789101112131415161718192021222324252627282930
  1. import { Input, Card, Button, Space } from 'antd';
  2. import { useEffect, useState } from 'react';
  3. import { connect } from 'react-redux';
  4. import { actionAddCategory } from '../action';
  5. const ACategory = ({addCat}) => {
  6. const [nameCat, setNameCat] =useState('');
  7. const clearInput = () => {
  8. setNameCat('');
  9. }
  10. return (
  11. <div >
  12. <Card type="inner" title="Добавить категорию">
  13. <div>Введите название категории</div>
  14. <Input onChange={ (e) => setNameCat(e.target.value)}/>
  15. <Space>
  16. <Button type="primary" onClick={() => addCat(nameCat)}>Сохранить изменения</Button>
  17. <Button type="primary" onClick={clearInput} >Очистить поле</Button>
  18. </Space>
  19. </Card>
  20. </div>
  21. )
  22. }
  23. const AddCategory = connect(null, {addCat: actionAddCategory})(ACategory);
  24. export default AddCategory;