Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6213

Too many re-renders. When setting state

$
0
0

I'm trying to make an e-commerce app using expo with typescript and I'm having issues with loading my categories page.There's two ways which one can access the category page

  1. Through bottom nav - this one works fine
  2. Through buttons on the home page

Trying to setState based off the params that's coming in through the homepage but it's giving me the Too many re-renders error.Below is the code that I currently have for it.

The default needs to be there because of the first method of entering the category page, I've tried putting a conditional as the default category, but category wont change the second time if being accessed through the home page again.

export default function CategoryList(props: Props) {  let { params } = useRoute<StackRouteProp<'Home'>>()  const [currentCategory, setCategory] = useState({categories: Categories[0]});  if (params) {    setCategory({categories: params.categories})  }}

Viewing all articles
Browse latest Browse all 6213

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>