0

I'm learning redux. I updated my application to react-router-dom v6. It turned out that match.params does not work. How should I change my code to be able to add a new column after the list ID. I know that params has been replaced with useParams, but how should I use that in this code? Can anyone help me out, please?

import {connect} from 'react-redux';

import List from './List';
import {getColumnsForList, createActionAddColumn} from '../../redux/columnsRedux';

const mapStateToProps = (state, props) => {
  const id = props.match.params.id;
  const filteredLists = state.lists.filter(list => list.id == id);
  const listParams = filteredLists[0] || {};

  return {
    ...listParams,
    columns: getColumnsForList(state, id),
  };
};

const mapDispatchToProps = (dispatch, props) => ({
  addColumn: title =>
    dispatch(
      createActionAddColumn({
        listId: props.match.params.id,
        title,
      })
    ),
});

export default connect(mapStateToProps, mapDispatchToProps)(List);
oli
  • 9
  • 2

0 Answers0