Component Logic - Fetch data

When you create a component in Clutch (either code or composition), you can fetch data using component logic or add your logic to the definition of your code component.

To add component logic, open the component configuration menu.

Select the Code option under Logic.

Add your Logic to make a fetch request. I make my fetch request in a useEffect, set the response to JSON format, and then set that data to a state using the useState.

  let [planet, setPlanet] = React.useState(null)

  React.useEffect(() => {
      .then(response => response.json())
      .then(data => setPlanet(data))
  }, [])


The console.log will display the planet data to the console.