Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

163
Visualizações
Props Match Params Id can't be read and Props.id is Undefined

If I am using const currentUserId = props.id then the error will be props.match is undefined, and the variable "userId" even is undefined when i am trying to console log. enter image description here

Then, I using props.match.params.id the code can't even being read, it's only blank enter image description here

Im also trying to modify the code become const currentUserId = props.computedMatch.params.id; but nothing works enter image description here

My code:

import React, {useContext, useState, useEffect} from 'react';
import { GlobalContext } from '../context/GlobalState';
import { Link, useNavigate } from 'react-router-dom';
import { v4 as uuid } from 'uuid';
import {
  Form,
  FormGroup,
  Label,
  Input,
  Button
} from 'reactstrap';

export const EditUser = (props) => {
  const [selectedUser, setSelectedUser] = useState({
    id: '',
    name: ''
  });
  const { users, editUser } = useContext(GlobalContext);
  const history = useNavigate();
  const currentUserId = props.match.params.id;

  useEffect(() => {
    const userId = currentUserId;
    console.log(typeof userId);
    const selectedUser = users.find(user => user.id === Number(userId))
    setSelectedUser(selectedUser)
    console.log(selectedUser);
  }, [currentUserId, users])

  const onSubmit = () => {
  
    history('/');
  }

  const onChange = (e) => {

  }
  return (
    <Form onSubmit={onSubmit}>
      <FormGroup>
        <Label>Nama</Label>
        <Input type='text' onChange={onChange} placeholder='Ganti Nama Disini!'></Input>
      </FormGroup>
      <Button type='submit'>Edit Data</Button>
      <Link to="/" className="btn btn-danger ml-2" style={{ marginLeft: "10px"}}>Cancel</Link>
    </Form>
  )
}
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

use withRouter

import React, {useContext, useState, useEffect} from 'react';
import { GlobalContext } from '../context/GlobalState';
import { Link, useNavigate } from 'react-router-dom';
import { withRouter } from 'react-router'; // here added
import { v4 as uuid } from 'uuid';
import {
  Form,
  FormGroup,
  Label,
  Input,
  Button
} from 'reactstrap';

const EditUser = (props) => {  // here changed
  const [selectedUser, setSelectedUser] = useState({
    id: '',
    name: ''
  });
  const { users, editUser } = useContext(GlobalContext);
  const history = useNavigate();
  const currentUserId = this.props.match.params.id;

  useEffect(() => {
    const userId = currentUserId;
    console.log(typeof userId);
    const selectedUser = users.find(user => user.id === Number(userId))
    setSelectedUser(selectedUser)
    console.log(selectedUser);
  }, [currentUserId, users])

  const onSubmit = () => {
  
    history('/');
  }

  const onChange = (e) => {

  }
  return (
    <Form onSubmit={onSubmit}>
      <FormGroup>
        <Label>Nama</Label>
        <Input type='text' onChange={onChange} placeholder='Ganti Nama Disini!'></Input>
      </FormGroup>
      <Button type='submit'>Edit Data</Button>
      <Link to="/" className="btn btn-danger ml-2" style={{ marginLeft: "10px"}}>Cancel</Link>
    </Form>
  )
}

export default withRouter(EditUser); // here added

about 4 years ago · Juan Pablo Isaza Relatório

0

i hope this will fix

import { useParams } from 'react-router-dom';
const { id: currentUserId } = useParams();
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda