Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

247
Views
change variable value with axios, useeffect, and usestate

i'm newbie here, i'm stuck. i want to change value from false to true, to stop shimmering when data sucessfully to load.

i have action like this

import axios from "axios";
import { CONSTANT_LINK } from "./constants";
import { GET } from "./constants";
import { ERROR } from "./constants";
import { connect } from 'react-redux';

export const addData = () => {
  return (dispatch) => {
    axios
      .get(CONSTANT_LINK)
      .then((res) => {
        dispatch(addDataSuccess(res.data));
      })
      .catch((err) => {
        dispatch(errorData(true));
        console.log("error");
      });
  };
};

const addDataSuccess = (todo) => ({
  type: GET,
  payload: todo,
});

const errorData = (error) => ({
  type: ERROR,
  payload: error,
});

and this is my homepage which influential in this matter

const [shimmerValue, setShimmerValue] = useState(false)
useEffect(() => { 
    setShimmerValue(true)
    dispatch(addData());
  }, []);
 <ShimmerPlaceholder visible={shimmerValue} height={20}>
            <Text style={styles.welcomeName}>Welcome,Barret</Text>
          </ShimmerPlaceholder>

i dont understand how it works

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You can pass callback like this

const [shimmerValue, setShimmerValue] = useState(false);

const updateShimmerValue = () => {
  setShimmerValue(true);
}
useEffect(() => { 
    // setShimmerValue(true) // remove this from here
    dispatch(addData(updateShimmerValue)); // pass callback as param here
  }, []);

Callback call here like

export const addData = (callback) => {
  return (dispatch) => {
    axios
      .get(CONSTANT_LINK)
      .then((res) => {
        ....
        callback(); // trigger callback like this here
      })
      .catch((err) => {
        ....
      });
  };
};
about 4 years ago · Juan Pablo Isaza Report

0

you can use it:

const [shimmerValue, setShimmerValue] = useState(false)
useEffect(() => {
    setState(state => ({ ...state, shimmerValue: true }));
    dispatch(addData());
}, [shimmerValue]);
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!