1

I am try to set a callback in child component, but when call this callback function, state is not updated, that is state in initial state.

Why this is that and how to resolve this problem ?

// calback
const resizeColumn = useCallback(nextWidth => {
    console.log(columns); // log empty array, that is initial value why!?
}, [columns]);


function initColumns(newColumns: Array<IColumn>) {
    return newColumns.map((item, idx) => {
        const column: IColumn = {...item, ...(props.columnsConfig[item.key] || {})};

        if (!column.hasOwnProperty("sorter") && props.sortable && !column.sorter)
            column.sorter = Boolean(props.onChangeSort) || sorter;

        column.title = t(column.title);
        column.render = renderCell(column);
        column.required = Boolean(column.fixed);
        column.width = props.defaultColumnWidth;
        column.translateData = props.translateDataSource;

        column.onHeaderCell = column => ({
            column,
            onResize: nextWidth => resizeColumn(nextWidth) // 
        }); // set callback to child

        return column;
    }).sort((a, b) => +Boolean(b.fixed) - +Boolean(a.fixed));
}

set callback to child. screenshot

callback, screenshot

Tahir Dev
  • 11
  • 2

0 Answers0