Я пытаюсь преобразовать компонент класса в функциональный компонент, поскольку мой код в основном основан на функциональных компонентах.
Я знаю как изменить другие, более распространенные элементы, такие как состояние и функции, но эти два блока кода я не совсем уверен, как конвертировать. После моих изменений функция изменения размера теперь точно не работает.
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
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Создайте три столбца одинакового размера (изменяемого размера) [дубликат]
Anonymous » » в форуме CSS - 0 Ответы
- 98 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Изменение пользовательского интерфейса по умолчанию компонента DatePicker ANTD
Anonymous » » в форуме Html - 0 Ответы
- 15 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Изменение пользовательского интерфейса по умолчанию компонента DatePicker ANTD
Anonymous » » в форуме CSS - 0 Ответы
- 8 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Изменение пользовательского интерфейса по умолчанию компонента DatePicker ANTD
Anonymous » » в форуме Html - 0 Ответы
- 11 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Изменение пользовательского интерфейса по умолчанию компонента DatePicker ANTD
Anonymous » » в форуме CSS - 0 Ответы
- 21 Просмотры
-
Последнее сообщение Anonymous
-