question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Toggling the checkboxes is not working when calling a function within the handelOnPress function!

See original GitHub issue

Hey @WrathChaos ,

I have a Flatlist that has some BouncyCheckbox components.

 const handelWorkToDo = (service, isChecked) => {
    if (isChecked) {
      console.log('add service');
      setWorkToDo([...workToDo, service]);
    } else {
      console.log('remove service');
      const isAvailable = (item) => item.id === service.id;
      R.filter(isAvailable, workToDo);
    }
  };

const Service = ({ id, title, duration }) => (
    <BouncyCheckbox
      fillColor="red"
      iconStyle={{ borderColor: 'red' }}
      key={id}
      onPress={(isChecked) =>
        handelWorkToDo({ id, title, duration }, isChecked)
      }
      style={{ paddingBottom: 10 }}
      text={`${title} -> ${duration}`}
      textStyle={{
        textDecorationLine: 'none',
      }}
    />
  );

const renderItem = ({ item }) => <Service {...item} />;

<FlatList
        data={DATA}
        renderItem={renderItem}
        keyExtractor={(item) => item.id}
        style={{ padding: 2 }}
/>


Whats happening is that when when I call the setWorkToDo([...workToDo, service]) or R.filter(isAvailable, workToDo) within the handelWorkToDo function, checkbox state is not being changed.

however if I remove/comment out those functions, the checkboxes are being checked without issues.

I would like to know if there is something missing within my code or If you have a fix for that.

Thank you 😃

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:13 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
husseinmansour6commented, May 8, 2022

Hey @WrathChaos ,

Thanks for the quick reply!

I had to do some work around for it to work as expected however it would be nice to support that within ur lib.

I took a look into the Manual check state and I saw that you are using one checkbox to toggle on/off with a useState hook. It would be nice to have an example of using multiple checkboxes that can toggle them with useState hook.

Thank you 😃

1reaction
husseinmansour6commented, May 26, 2022

So, I was able to run it and just created a PR for my changes. Please take a look here and let me know your thoughts 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Checkbox toggle content section not working for all checkboxes
I have created 4 checkbox toggle with details but ...
Read more >
How To Use Checkboxes In Google Sheets - Ben Collins
Learn how to use the Google Sheets checkbox to toggle cells checked/unchecked in your Google Sheets and make them more interactive.
Read more >
ARIA: checkbox role - Accessibility - MDN Web Docs - Mozilla
The checkbox role is for checkable interactive controls. ... two states ("checked" or "not checked"), with an indeterminate state settable ...
Read more >
React Tutorial – How to Work with Multiple Checkboxes
Whenever we click on the checkbox the handleOnChange handler function will be called which we use to set the value of isChecked state....
Read more >
How to handle HTML checkbox events | HTML Form Guide
There are two events that you can attach to the checkbox to be fired once the checkbox value has been changed they are...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found