score:0
inside person.js you can delete by using a callback to get the id
<button onclick={()=>deletecontact(person.id)}>delete {person.id} </button>
import react from 'react'
import axios from 'axios'
const baseurl = 'http://localhost:3001/persons'
const deletecontact = (id)=>{
const request = axios.delete('{$baseurl}/${id}')
request.then(response =>response.data)
}
const person = ({ person, deletecontact }) => {
console.log("person.js props "+person.id)
return (
<li>
{person.name} {person.number}
<button onclick={()=>deletecontact(person.id)}>delete {person.id} </button>
</li>
)
}
export default person
Source: stackoverflow.com
Related Query
- Reactjs and axios. Delete object from json database
- Delete data from API with Axios and ReactJS
- Using data from API JSON object using Axios and React
- How to display, add and delete items from JSON file using ReactJs
- Prevent duplicates from json array with reactjs and axios
- how to loop throgh array of object from axios json respone in react js and set them in div?
- Function to add and delete from JSON object
- How can I delete an entire json object from an array of json objects and write it out to file?
- How to get variable colors from database with Axios and then apply them in Scss - ReactJs
- React.js: loading JSON data with Fetch API and props from object array
- ReactJS - get json object data from an URL
- ReactJS and complex JSON object
- How can i get array of object from this data for state and count in reactjs
- How to make a react table whose rows and columns come from a JSON object
- Get object array from axios and using return value call another axios function and append the output to first result
- ReactJS access JSON object passed from other component
- How to update a function with useEffect (like componentDidUpdate) and use .map function to display from JSON file ReactJS
- How to save single object into state, from json end point axios
- node and reactjs axios server request returning index.html file instead of json
- How can i return a JSON object and a zipped folder simultaneously from on end point in spring boot
- ReactJS and axios, issues accessing nested objects from JSON response
- How to receive JSON Object from node and display it on client side in react?
- Correct way to React axios post with UUID and nested object in JSON payload?
- Can't access value from an array inside JSON object in Reactjs
- Add CSS style using className in Material UI component coming from dynamic json object in ReactJS
- How to add, edit, update, delete element from array javascript and reactjs
- I am trying to delete items from TODO app using axios and django
- React map object and embedded object from JSON and convert to single array for state
- Receive JSON Object from ReactJS on my Django BackEnd
- Fetch and display image in reactjs from django backend using json
More Query from same tag
- Advantages and Understanding of using Currying Function pattern in onClick Event handler in React
- Using Next.js next-routes, how to define a home route for the base web page?
- How to get the first and last visible date in React Big Calendar?
- Using bindActionCreators and mapDispatchToProps in a React functional component gives me undefined
- Use props inside emotion's css string template
- Errors show correctly on Graphiql but not returned to Apollo Client in react front end
- How to render html elements in Reactjs?
- Argument of type 'Element' is not assignable to parameter of type 'ReactElement<any>
- Get linebreaks/indents with react.renderToStaticMarkup?
- React: Calling Third-Party API (Behance) using Ajax
- i cant update the state in my parent component from my child (class) component
- extracting data using mapstatetoprops
- Use index.js to import multiple image assets in React
- Component to call all material-ui Icon in React
- Make list.js and react.js work together
- Reactjs show selected option by object
- wProps updating in react dev tools but conditional jsx not rendering correctly
- How to call function from another file in reactjs
- React JS - Live clock update
- Reasons for using svelte js
- Adding variable to script tag in React
- Set Hook in React Native
- Semantic UI React change default font
- How can I change the animation on a button in material UI?
- nextProps and NextState are always equivalent
- blue dot for current location in react-google-maps
- Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser for gatsby/typescript
- how to receive message from BackgroundJS and change state in ReactJS and Chrome extension?
- How to get data from RouteComponentProps
- How to add fade effect in react-table?