No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.
General Tech 10 Answers
General Tech 7 Answers
General Tech 3 Answers
General Tech 9 Answers
manpreet
Best Answer
2 years ago
I am very new to React. I am trying to make a reusable Checkbox component. These checkboxes are to send info to an API. I have a
GET
command onApp.JS
, to set state.Here is a simplified version of my API
I pass the props to the children like so:
I can make individual components for each checkbox and setting the
checked
state by setting individual state like so:But that means I have to make a component for each 'valve' in my API. Ideally I would like to have one Checkbox component that I can reuse for all my "valves".
I've made a semi-working component by specifying the name of the valve as a prop:
And here is my component that successfully passes the change to the API, however I need to dynamically set the last part of the setState
, otherwise all switches just get the state of valveA: