Skip to content

[Bug]: React router not rendering dynamic route #10123

Closed Answered by KennyMwendwaX
KennyMwendwaX asked this question in Q&A
Discussion options

You must be logged in to vote

The issue was the order of hooks.

Code example:

import {
  FaShoppingCart,
  FaFacebookF,
  FaTwitter,
  FaInstagram,
  FaHeart,
  FaStar,
  FaRegStar,
} from "react-icons/fa"
import { HiOutlineMinus, HiOutlinePlus } from "react-icons/hi"
import { useState, useEffect } from "react"
import { useParams } from "react-router-dom"
import { ItemTypes } from "../types/StoreTypes"
import formatCurrency from "../utils/formatCurrency"

export default function Item() {
  const { id } = useParams<{ id: string }>()
  const [item, setItem] = useState<ItemTypes | null>(null)
const [count, setCount] = useState(1)
  useEffect(() => {
    async function fetchItem() {
      const res = await fetch(`http://l…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by KennyMwendwaX
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
1 participant
Converted from issue

This discussion was converted from issue #10120 on February 21, 2023 19:14.