Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

link button not working second when i added new maincategory, it is rendering same component intead of going path #615

Open
dineshbhati61102 opened this issue May 5, 2023 · 0 comments

Comments

@dineshbhati61102
Copy link

import React, { useEffect, useState } from 'react'
import { Link } from 'react-router-dom'
import LeftNav from './LeftNav'
import { useDispatch, useSelector } from "react-redux"
import { GetMaincategoryAction } from "../../Store/Actions/MaincategoryAction"

const AdminMaincategories = () => {
const [Maicategories, setMaicategories] = useState([]);
const dispatch = useDispatch();
const { data, error } = useSelector(state => state.MaincategoryStateData);

function getAPIData(){
dispatch(GetMaincategoryAction())
if(data.length)
setMaicategories(data)
}

useEffect(() => {
getAPIData()
}, [data.length])

return (
<>




    <div className='col-md-10 table-responsive'>
      <h2 className='text-center text-primary'>Maincategories</h2>
      <Link to='/admin-add-maincategory' className='btn btn-primary text-light py-2 px-3 mb-2'>Add New</Link>

      <table className='table table-bordered'>
        <thead className='bg-primary text-light'>
          <tr>
            <th>ID</th>
            <th>Name</th>
            <th>Edit</th>
            <th>Delete</th>

          </tr>
        </thead>
        <tbody>

          {error ? <h5 className='alert alert-danger text-center mt-5'>{error}</h5> :

          Array.isArray(Maicategories) && Maicategories.map((elem, index) => {
              return <tr key={index}>
                <td>{elem._id}</td>
                <td>{elem.name}</td>
                <td> <Link to="/admin-update-maincategory" className='btn btn-primary text-light py-2 px-3 mb-2'>Update</Link></td>
                <td> <button className='btn btn-primary text-light'>Delete</button></td>
              </tr>
            })}

        </tbody>
      </table>
    </div>
  </div>
</>

)
}

export default AdminMaincategories

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant