score:0
You have to persist on server side you are only setting the state so change your handleClick function like this using axios
handleClick: function(event) {
// post to server using ajax here
this.setState({liked: !this.state.liked, id: this.prop.id});
liked = this.state.liked;
id = this.prop.id;
axios.post('/YOUR_LIKE_UNLIKE_API_END_POINT', {
liked: liked,
id: id
}).catch(function (error) {
this.setState({liked: !this.state.liked, id: this.prop.id});
});
},
Source: stackoverflow.com
Related Query
- how to render a react component using ReactDOM Render
- How to pass the match when using render in Route component from react router (v4)
- Error using component done with react,redux and react-redux and build with webpack in react application
- React render component using its name
- Testing an error thrown by a React component using testing-library and jest
- Using CSSTransitionGroup on a react component is giving error
- How to wait for complete render of React component in Mocha using Enzyme?
- How to render a React component (ES6 API) directly using ReactDOM?
- Why do my styled component keyframes error with ts-styled-plugin(9999) in react when using percentage instead of TO/FROM
- React component function returning JSX causes error when used in render method of ES6 class React component
- I got an error for using React.useRef inside a react function component
- Error using useEffect in react functional component
- Why React still render the child component with Error Boundary
- React router v4.2.2: using a string instead of function inside component prop of Route results in error
- Why does the render function in react is called twice when using the component strategy?
- How can you render a react component using dynamic name?
- React component render twice using useState
- How to render a component using innerHTML in React jsx
- Converting class component to functional component using react hooks (useRef)—how to avoid "undefined" error
- How to render different component onClick using React material-ui Drawer list?
- How to mock properly with Jest a React component using render props
- React router 4 custom component giving render function error
- Trying to render Firestore information in React component - utilization of useRef() not re-rendering and useState() raises error
- Using setInterval in React delays component render
- Type error when using render when defining table columns in material table React
- Error when testing a React Parent that contains a Child React Redux Component using Enzyme Mount
- react render error ReactDOM.render(): Invalid component element
- React Material-ui library Error Received `true` for a non-boolean attribute `active`. while using Stepper component
- Render a React Component Using Multiple Ternary Operator
- Error rendering react component using Typescript and WebPack
More Query from same tag
- Ant Design: How can I handle Button in Card extra onClick event?
- jsx render error with loop: elements not defined
- React: Uncaught TypeError: Cannot read property '_currentElement' of null
- React trying to use .map to populate data from multiple APIs into the same mapped container
- Render data in ReactJS
- let variable is not defined
- React Hooks & UseEffect not updating display with socketIO data. Only renders elements in array
- React TypeError: Cannot read properties of undefined (reading 'name')
- React Router 4 -- listen to route actions and programmatically continue/stop routing
- Why isn't a state variable displaying in a header but a constant is?
- React Component calling method to a different component
- Material-UI Autocomplete: how to set as a required field
- What is right to use Spread operator or Object.assign in Redux?
- How to send radio button's value into state and change the value when another radio button is clicked
- Allow display of multiple data attributes in tooltip of Chart.js
- Update an antd RangePicker from outside the component
- Why is my npm build for test picking up production properties?
- React useEffect Missing Dependency
- Express overwrites react-router client side routes
- React antd Upload input required error with default list
- Module not found: Can't resolve 'fs' in '.../node_modules/destroy' using Next.js mysql Express React
- Axios delete call returns 405 and I tried to delete node using id but it's not deleting
- forceUpdate warning on Grid
- Kindly help,am having issues when I try to install material UI in my react project
- getting a field from a json object using a "address string" in JavaScript
- To pass values into useNavigate() react-router-dom and use it in the redirected component
- How to render based on a condition in Typescript?
- why does my react router links work in drawer but not header
- Testing component with custom hook
- onClick not working React js