How to pass checkbox state to onClick Function in React
You can pass event object from onClick handler to action method as below:
<input type="checkbox"
name={field}
id={field}
onClick={(event) => this.buildTemplate(objectA, objectB, event)}
/>
checkbox onclick changing only after refreshing react js
Your code is quite unorganized and muddled, but essentially you just need to trigger refetching the data once it is updated. The getData
function already does this when the component mounts. Call this function after the successful POST request in the handleCheckClick
handler.
handleCheckClick = (e, stateVal, index) => {
...
const headers = {
Authorization: `token xxxxxx`
};
axios
.post(
"customer/symptoms-submit/",
data,
{ headers }
)
.then(() => {
alert("symptom was submitted");
this.getData(); // <-- trigger refetch data here
})
.catch((error) => {
alert("Cannot add symptoms again");
});
};
React Checkbox not sending onChange
To get the checked state of your checkbox the path would be:
this.refs.complete.state.checked
The alternative is to get it from the event passed into the handleChange
method:
event.target.checked
Related Topics
If Check Box Checked Disable Other, If Unchecked Enable All in React
Angular:How to Add/Remove Files in the Angular
How to Remove Image from Browser Cache
How to Know If Browser Tab Is Already Open Using JavaScript
How to Capture the Browser Window Close Event
415 (Unsupported Media Type) With Rest Post Request
How to Fix: Typeerror: Document.Queryselector(...) Is Null
How to Get List of All Timezones in JavaScript
Webaudio - Seamlessly Playing Sequence of Audio Chunks
React How to Fix Failed Prop Type - Invalid Prop of Type String Expected Object
Is There Any Workaround (Or Hack) to Make the Audio Autoplay on Chrome, Firefox and Safari
Switch Fontawesome Icon on Click, Not Working
How to Escape an Ampersand in a JavaScript String So That the Page Will Validate Strict
Javascript Dashes in Phone Number
How to Get the Value of Li on Dropdown Menu Click in Laravel Using Jquery