Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

160
Views
Props Match Params Id no se puede leer y Props.id no está definido

Si estoy usando const currentUserId = props.id , entonces el error será props.match no está definido , y la variable "userId" incluso no está definida cuando intento iniciar sesión en la consola. ingrese la descripción de la imagen aquí

Luego, uso props.match.params.id , el código ni siquiera se puede leer, solo está en blanco ingrese la descripción de la imagen aquí

También estoy tratando de modificar el código para que se convierta en const currentUserId = props.computedMatch.params.id; pero nada funciona ingrese la descripción de la imagen aquí

Mi código:

 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 answers
Answer question

0

usar con enrutador

 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 Report

0

espero que esto se arregle

 import { useParams } from 'react-router-dom'; const { id: currentUserId } = useParams();
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!