Я пытаюсь преобразовать компонент класса в функциональный компонент, поскольку мой код в основном основан на функциональных компонентах.
Я знаю как изменить другие, более распространенные элементы, такие как состояние и функции, но эти два блока кода я не совсем уверен, как конвертировать. После моих изменений функция изменения размера теперь точно не работает.
handleResize = index => (e, { size }) => {
this.setState(({ columns }) => {
const nextColumns = [...columns];
nextColumns[index] = {
...nextColumns[index],
width: size.width,
};
return { columns: nextColumns };
});
};
render() {
const columns = this.state.columns.map((col, index) => ({
...col,
onHeaderCell: column => ({
width: column.width,
onResize: this.handleResize(index),
}),
}));
return ;
}
}
Это после моей попытки изменить код. Благодарим за любую помощь!
import React, { useState } from 'react';
import './AccountPortfolio.scss';
import HeaderTitle from '../../../components/HeaderTitle/HeaderTitle';
import Footer from '../../../components/Footer/Footer';
import Sidebar from '../../../components/Navigation/Sidebar/Sidebar';
import HeaderComponent from '../../../components/Navigation/HeaderComponent/HeaderComponent';
import { Layout, Table, Breadcrumb } from 'antd';
import { Resizable } from 'react-resizable';
// import 'react-resizable/css/styles.css';
const ResizableTitle = (props) => {
const { onResize, width, ...restProps } = props;
if (!width) {
return ;
}
return (
}
onResize={onResize}
draggableOpts={{ enableUserSelectHack: false }}
>
);
};
const { Content } = Layout;
function AccountPortfolioPage(props) {
const [columns, setColumns] = useState([
{
title: 'Date',
dataIndex: 'date',
width: 200,
},
{
title: 'Amount',
dataIndex: 'amount',
width: 100,
sorter: (a, b) => a.amount - b.amount,
},
{
title: 'Type',
dataIndex: 'type',
width: 100,
},
{
title: 'Note',
dataIndex: 'note',
width: 100,
},
{
title: 'Action',
key: 'action',
render: () => Delete,
},
]);
const components = {
header: {
cell: ResizableTitle,
},
};
const data = [
{
key: 0,
date: '2018-02-11',
amount: 120,
type: 'income',
note: 'transfer',
},
{
key: 1,
date: '2018-03-11',
amount: 243,
type: 'income',
note: 'transfer',
},
{
key: 2,
date: '2018-04-11',
amount: 98,
type: 'income',
note: 'transfer',
},
];
const handleResize = (index) => (e, { size }) => {
setColumns(({ columns }) => {
const nextColumns = [...columns];
nextColumns[index] = {
...nextColumns[index],
width: size.width,
};
return { columns: nextColumns };
});
};
const columnsData = columns.map((col, index) => ({
...col,
onHeaderCell: (column) => ({
width: column.width,
onResize: handleResize(index),
}),
}));
return (
MMS
Account Portfolio
);
}
export default AccountPortfolioPage;
Подробнее здесь: https://stackoverflow.com/questions/640 ... -component
Преобразование таблицы изменяемого размера AntD в использование функционального компонента ⇐ CSS
Разбираемся в CSS
1710657879
Гость
Я пытаюсь [b]преобразовать компонент класса[/b] в [b]функциональный компонент[/b], поскольку мой код в основном основан на функциональных компонентах.
Я знаю как изменить другие, более распространенные элементы, такие как состояние и функции, но эти два блока кода я не совсем уверен, как конвертировать. После моих изменений функция изменения размера теперь точно не работает.
handleResize = index => (e, { size }) => {
this.setState(({ columns }) => {
const nextColumns = [...columns];
nextColumns[index] = {
...nextColumns[index],
width: size.width,
};
return { columns: nextColumns };
});
};
render() {
const columns = this.state.columns.map((col, index) => ({
...col,
onHeaderCell: column => ({
width: column.width,
onResize: this.handleResize(index),
}),
}));
return ;
}
}
[b]Это после моей попытки изменить код. Благодарим за любую помощь![/b]
import React, { useState } from 'react';
import './AccountPortfolio.scss';
import HeaderTitle from '../../../components/HeaderTitle/HeaderTitle';
import Footer from '../../../components/Footer/Footer';
import Sidebar from '../../../components/Navigation/Sidebar/Sidebar';
import HeaderComponent from '../../../components/Navigation/HeaderComponent/HeaderComponent';
import { Layout, Table, Breadcrumb } from 'antd';
import { Resizable } from 'react-resizable';
// import 'react-resizable/css/styles.css';
const ResizableTitle = (props) => {
const { onResize, width, ...restProps } = props;
if (!width) {
return ;
}
return (
}
onResize={onResize}
draggableOpts={{ enableUserSelectHack: false }}
>
);
};
const { Content } = Layout;
function AccountPortfolioPage(props) {
const [columns, setColumns] = useState([
{
title: 'Date',
dataIndex: 'date',
width: 200,
},
{
title: 'Amount',
dataIndex: 'amount',
width: 100,
sorter: (a, b) => a.amount - b.amount,
},
{
title: 'Type',
dataIndex: 'type',
width: 100,
},
{
title: 'Note',
dataIndex: 'note',
width: 100,
},
{
title: 'Action',
key: 'action',
render: () => Delete,
},
]);
const components = {
header: {
cell: ResizableTitle,
},
};
const data = [
{
key: 0,
date: '2018-02-11',
amount: 120,
type: 'income',
note: 'transfer',
},
{
key: 1,
date: '2018-03-11',
amount: 243,
type: 'income',
note: 'transfer',
},
{
key: 2,
date: '2018-04-11',
amount: 98,
type: 'income',
note: 'transfer',
},
];
const handleResize = (index) => (e, { size }) => {
setColumns(({ columns }) => {
const nextColumns = [...columns];
nextColumns[index] = {
...nextColumns[index],
width: size.width,
};
return { columns: nextColumns };
});
};
const columnsData = columns.map((col, index) => ({
...col,
onHeaderCell: (column) => ({
width: column.width,
onResize: handleResize(index),
}),
}));
return (
MMS
Account Portfolio
);
}
export default AccountPortfolioPage;
Подробнее здесь: [url]https://stackoverflow.com/questions/64021620/converting-antd-resizable-table-to-using-functional-component[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия