<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Topics tagged with state]]></title><description><![CDATA[A list of topics that have been tagged with state]]></description><link>https://lankadevelopers.lk/tags/state</link><generator>RSS for Node</generator><lastBuildDate>Mon, 16 Mar 2026 02:23:43 GMT</lastBuildDate><atom:link href="https://lankadevelopers.lk/tags/state.rss" rel="self" type="application/rss+xml"/><pubDate>Invalid Date</pubDate><ttl>60</ttl><item><title><![CDATA[How to update individually buttons icons got from a same component in React]]></title><description><![CDATA[<p dir="auto">I have a View All page. The page has a table with user data with actions that can be performed. The button has two different icons. Spinner icon and a default icon. I want to change the icon of the button until the task executes.</p>
<p dir="auto">Ex: Showing spinner icon until M_1's disabling/deleting process works and showing back the lock/trash icon.</p>
<p dir="auto">I know how to update one button icon by putting useState. When 1 row has 2 buttons that mean 2 useStates. So 2 rows mean 4 useStates. But that's not practical noh. I want to know how to do it the correct way.</p>
<p dir="auto">Table with buttons:<br />
<img src="https://ibb.co/qMsBgZr" alt="table with buttons" class=" img-responsive img-markdown" /></p>
<p dir="auto">View All Page:</p>
<pre><code>import React, { useEffect, useState } from 'react'
import {
  CButton,
  CCard,
  CCardBody,
  CCardHeader,
  CCol,
  CRow,
  CSpinner,
  CTable,
  CTableBody,
  CTableDataCell,
  CTableHead,
  CTableHeaderCell,
  CTableRow,
} from '@coreui/react'
import CIcon from '@coreui/icons-react'
import { cilTrash, cilLockLocked } from '@coreui/icons'

const ViewAll = () =&gt; {
  const [usersData, setUsersData] = useState({})

  const [disabled, setDisabled] = useState(false)

  const handleLoadMembers = async () =&gt; {
    try {
      const _data = await fetch('http://localhost:4000/api/v1/member/list', {
        method: 'GET',
        headers: {
          'Content-Type': 'application/json',
          Authorization: 'Bearer ' + localStorage.getItem('token'),
        },
      })

      if (_data.status !== 200) {
        throw new Error()
      }

      const data = await _data.json()
      setUsersData(data.members)
    } catch (err) {
      console.error(err)
    }
  }

  const handleDelete = async (id) =&gt; {
    alert('clicked')
    try {
      const _data = await fetch('http://localhost:4000/api/v1/member/remove/' + id, {
        method: 'GET',
        headers: {
          'Content-Type': 'application/json',
          Authorization: 'Bearer ' + localStorage.getItem('token'),
        },
      })
      window.location.reload()

      console.log(_data)
    } catch (err) {
      console.error(err)
    }
  }

  useEffect(() =&gt; {
    handleLoadMembers()
  }, [])

  return (
    &lt;CRow&gt;
      &lt;CCol xs={12}&gt;
        &lt;CCard className="mb-4"&gt;
          &lt;CCardHeader&gt;
            &lt;strong&gt;All Members&lt;/strong&gt;
          &lt;/CCardHeader&gt;

          {usersData.length &gt; 0 ? (
            &lt;CCardBody&gt;
              &lt;p className="text-medium-emphasis small"&gt;Here the all members of your community.&lt;/p&gt;
              &lt;CTable hover bordered&gt;
                &lt;CTableHead color="dark"&gt;
                  &lt;CTableRow&gt;
                    &lt;CTableHeaderCell scope="col"&gt;Member ID&lt;/CTableHeaderCell&gt;
                    &lt;CTableHeaderCell scope="col"&gt;Name&lt;/CTableHeaderCell&gt;
                    &lt;CTableHeaderCell scope="col"&gt;Email&lt;/CTableHeaderCell&gt;
                    &lt;CTableHeaderCell scope="col"&gt;Actions&lt;/CTableHeaderCell&gt;
                  &lt;/CTableRow&gt;
                &lt;/CTableHead&gt;
                &lt;CTableBody&gt;
                  {usersData.map((item, index) =&gt; {
                    return (
                      &lt;CTableRow key={index}&gt;
                        &lt;CTableHeaderCell scope="row"&gt;M_{item.index}&lt;/CTableHeaderCell&gt;
                        &lt;CTableDataCell&gt;{item.name}&lt;/CTableDataCell&gt;
                        &lt;CTableDataCell&gt;{item.email}&lt;/CTableDataCell&gt;
                        &lt;CTableDataCell class="d-flex justify-content-evenly"&gt;
                          &lt;CButton
                            color="danger"
                            size="sm"
                            disabled={disabled}
                            onClick={() =&gt; handleDelete(item._id)}
                          &gt;
                            {disabled ? (
                              &lt;CSpinner
                                component="span"
                                className="me-2"
                                size="sm"
                                aria-hidden="true"
                              /&gt;
                            ) : (
                              &lt;CIcon icon={cilTrash} className="me-2" /&gt;
                            )}
                            Delete
                          &lt;/CButton&gt;
                          &lt;CButton
                            color="warning"
                            size="sm"
                            disabled={disabled}
                            onClick={() =&gt; handleDelete(item._id)}
                          &gt;
                            {disabled ? (
                              &lt;CSpinner
                                component="span"
                                className="me-2"
                                size="sm"
                                aria-hidden="true"
                              /&gt;
                            ) : (
                              &lt;CIcon icon={cilLockLocked} className="me-2" /&gt;
                            )}
                            Disable
                          &lt;/CButton&gt;
                        &lt;/CTableDataCell&gt;
                      &lt;/CTableRow&gt;
                    )
                  })}
                &lt;/CTableBody&gt;
              &lt;/CTable&gt;
            &lt;/CCardBody&gt;
          ) : (
            'No data'
          )}
        &lt;/CCard&gt;
      &lt;/CCol&gt;
    &lt;/CRow&gt;
  )
}

export default ViewAll
</code></pre>
]]></description><link>https://lankadevelopers.lk/topic/889/how-to-update-individually-buttons-icons-got-from-a-same-component-in-react</link><guid isPermaLink="true">https://lankadevelopers.lk/topic/889/how-to-update-individually-buttons-icons-got-from-a-same-component-in-react</guid><dc:creator><![CDATA[nipooNM]]></dc:creator><pubDate>Invalid Date</pubDate></item></channel></rss>