re: Run Function after useEffect to Manipulate Data? VIEW POST


You can do everything in the effect function:

import React, { useState, useEffect } from 'react';
import axios from 'axios';
import {KelvinConvert} from './MathConversions';

const LocalWeather = () => {
    const [openWeather, setWeather] = useState({});

    useEffect(() => {
        .then(data => {
            setWeather( KelvinConvert(data.data));
    }, []); //  Run once on load

    return (
        <ul id="weather-container">
            <KelvinConvert />  // Trying to add converted temperature here
            <li>{openWeather.main && openWeather.main.temp}&deg;F</li>
            <li>{openWeather.weather && openWeather.weather[0].main}</li>

export default LocalWeather;

If you get this error:

Line 11:8: React Hook useEffect has a missing dependency: 'KelvinConvert'. Either include it or remove the dependency array react-hooks/exhaustive-deps

You can safely ignore it because since your Effect runs only once, you don't need to keep track of the dependency.

Code of Conduct Report abuse