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

149
Views
React one item's loading shows in every item in loop

I have a react page where I show all FAQs items in a list within a javascript map loop. There are two buttons yes or no. Users can vote an answer yes or no. So whenever the user clicks the buttons a loading indicator will show.

Faqs Page:

<>
{
faqs.map((faq) => (
 <Faq key={faq.id} faq={faq} />
))
}
</>

Faq component:

interface IProps {
  faq: IFaq;
}

const FaqVoteSection: React.FC<IProps> = (props) => {
  const { faq } = props;
  const dispatch = useDispatch();
  const { faqVoteLoading } = useSelector((state: AppState) => state.user);

  const [loadingState, setLoadingState] = useState<
    'yesvote-loading' | 'novote-loading' | 'not-loading'
  >('not-loading');

  const onVoteSubmit = async (vote: boolean) => {
    if (faq) {
      dispatch(
        faqVoteApiAction({
          faq_id: faq.id,
          vote,
        })
      );
      setLoadingState('not-loading');
    }
  };

  const onYesVotePress = () => {
    setLoadingState('yesvote-loading');
    onVoteSubmit(true);
  };

  const onNoVotePress = async () => {
    setLoadingState('novote-loading');
    await onVoteSubmit(false);
  };

  return (
    <FlexContainer>
      <SolidButton
        type={faq.vote === 'yes' ? 'primary' : 'default'}
        size="small"
        onClick={onYesVotePress}
        loading={loadingState === 'yesvote-loading' && faqVoteLoading}
      >
        Yes
      </SolidButton>
      <Gap />
      <SolidButton
        size="small"
        type={faq.vote === 'no' ? 'primary' : 'default'}
        onClick={onNoVotePress}
        loading={loadingState === 'novote-loading' && faqVoteLoading}
      >
        No
      </SolidButton>
    </FlexContainer>
  );
};

Now when I click a vote button I want to show the loading only for that item. But the loading shows every item in the list. I think it's because of the map loop.

enter image description here

about 4 years ago · Juan Pablo Isaza
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!