API - add hardcode value for API response for development

0 votes
31 views
added Feb 21 in API by lcjr First Warrant Officer (11,830 points)

Simply change the useState([YOUR_HARDCODE_VALUE]);. Example shown below

const [apiResponseValue, setApiResponseValue] = useState(0);

Below is the full code:

 

import OtpListing from '../propertysearch/OtpListing';

// State to hold the API response value
const [apiResponseValue, setApiResponseValue] = useState(0); // Hardcoded value of 0

// Simulate API call using useEffect
useEffect(() => {
  // Simulated API call
  const fetchData = async () => {
    try {
      // Simulated API response
      const response = await fetch('your-api-endpoint');
      const data = await response.json();
      // Set the API response value to the state
      setApiResponseValue(data.value); // Assuming your API response has a key 'value'
    } catch (error) {
      console.error('Error fetching API:', error);
    }
  };

  // Call the fetchData function
  fetchData();
}, []); // Empty dependency array to execute only once on component mount


return (
    <>
      {apiResponseValue === 0 && <OtpListing />}
    </>
  );
}

 

lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...