Apply for Zend Framework Certification Training

ReactJs





 

Steps to delete users Data

Step 1 Add some code in userlist.jsx

 

import { useEffect, useState } from 'react'

import '../css/userlist.css'

import axios from 'axios'

const Userlist = ()=>{

    const [userData,getUserData] = useState('')

    useEffect(()=>{

        userlist()

    },[])

    const userlist = ()=>{

        axios.get('https://api.uncodecart.com/users/userlist').then((response)=>{

            getUserData(response.data.message)

        })

    }

    const handleDelete = (id)=>{

        console.log(id)

        axios.delete('https://api.uncodecart.com/users/deleteuser/'+id).then((response)=>{

            console.log(response)

            userlist()

        })

    }

    return(

        <>

        <table>

        <tr><th>Users id</th><th>First name</th><th>Last name</th><th>Email</th><th>Action</th></tr>

    {userData && userData.map((User)=>(

        

        <tr>

            <td>{User.users_id}</td>

            <td>{User.firstname}</td>

            <td>{User.lastname}</td>

            <td>{User.email}</td>

            <td>

                <input type='button' value="Delete" onClick={()=>{handleDelete(User.users_id)}}/>

            </td>

        </tr>

    ))}

        </table>

        </>

    )

}

 

export default Userlist


 

< First Getting Started With CodeIgniter URL Routing >



Ask a question



  • Question:
    {{questionlistdata.blog_question_description}}
    • Answer:
      {{answer.blog_answer_description  }}
    Replay to Question


Back to Top