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

168
Views
TypeError: Cannot read properties of undefined (reading 'push')

Error message

I was able to solve this issue using useNavigate

let params = useParams();
  let navigate = useNavigate();
  const dispatch = useDispatch();
  const productId = params.id;
  const [qty, setQty] = useState(1);
  const productDetails = useSelector((state) => state.productDetails);
  const { loading, error, product } = productDetails;
 
  useEffect(() => {
    dispatch(detailsProduct(productId));
  }, [dispatch, productId]);
 
  const addToCartHandler = () => {
    navigate(`/cart/${productId}?qty=${qty}`);
  };
  

but the page didn't show anything

Code

thank you

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

While you are using react functional componenets.you should use hooks

import {useHistory} from 'react-router-dom'
const App=()=>{
  const history=useHistory()
  const submit=()=>{
     history.push("/products/23")
  }
}

for react router v6

import {useNavigate} from 'react-router-dom'
const App=()=>{
  const navigate=useNavigate()
  const submit=()=>{
     navigate("/products/23") 
  }
}
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!