Skip to content Skip to sidebar Skip to footer

React Functional Components Props Value Not Updating

I am trying to simply render the props.item 's value based on parent state but it is always showing the initial value. However, inside useEffect the props.item has the updated valu

Solution 1:

could you please add a lil more, it does not cost any money if you add some:

  • code snippets.
  • expected behavior.
  • actual behavior.

Solution 2:

try:

constCarousel = ({activePageIndex}) => {
  useEffect(() => {
//Here it shows the updated value

  }, [activePageIndex]);
//Here it shows the updated valuereturn<divclassName="carousel-container">{activePageIndex}</div>;
};

exportdefaultCarousel;

Solution 3:

try passing the setActivePageIndex directly as props.

Ex-

functionApp() {
  const [activePageIndex, setActivePageIndex] = useState(0);

  return (
    <divclassName="App"><divclassName="app-content"><CarouselactivePageIndex={activePageIndex}onScroll={(e) => setActivePageIndex(e.target.value)}
        />
      </div></div>
  );
}

exportdefaultApp;

Post a Comment for "React Functional Components Props Value Not Updating"