1

Here is my code snippet

https://codesandbox.io/s/dropdown-primereact-gjcdm0?file=/src/demo/DropdownDemo.js

I am making an API call for my dropdown, Expected: The currency codes should be visible on drop down once I select it and also the options should be showing up

Actual: The currency is not visible on the dropdown, but the options are correctly fetched and placed in dropdown

Please let me know if I can persist the value onClick on the dropdown

2 Answers2

0

I fixed your Sandbox its now working: https://codesandbox.io/s/dropdown-primereact-forked-sjskrb?file=/src/demo/DropdownDemo.js

Melloware
  • 10,435
  • 2
  • 32
  • 62
-1

You need to remove the currency from the useEffect dependency array. Like so:

useEffect(() => {
    fetchData(currency);
  }, []);

If not the fetchData function is called every time the currency cahnges and this resets the dropdown.

rustyBucketBay
  • 4,320
  • 3
  • 17
  • 47
  • If I remove the dependency I wont get the updated currency exchange rates, I have updated my sandbox to display the data on change of dropdown data its working perfectly in terms of filling the dropdown and displaying the data but the selected value is not showing upon the dropdown after fetching from API. Please help – Lakshmi Jayarama Oct 28 '22 at 00:07
  • I posted your fixed Sandbox above – Melloware Oct 29 '22 at 13:40