JavaScript How to use setState in map function setstate function react,setstate functional component react,setstate function component,

I'm trying to use setState in map function what I want to make when I hit click button that makes states changed

I searched "In map function changed setState" in stackoverflow

but It was hard to understand..and apply my case

this.state = {
      categories: [
        {
          category: 'sports',
          ariticles: [],
          isClick: true
        },

...
...

 return (
      <div>
        <hr></hr>

        <div className="categoryBtn">
          {this.state.map(item => (
            <button
              onClick={
                () => this.setState(() => (item.isClick = false))
                // () => console.log((item.isClick = false))
                // this.setState(() => (item.isClick = !item.isClick))
              }
            >
              {' '}
              {item.category}
            </button>
          ))}

when I hit my button I got error ' this.state.map is not a function'

I expect when I hit button, isClick will be toggle

Answer:1

I run an e-commerce website and we have various third-party JavaScript that add click handlers to links and forms and then insert a delay to make sure the tracking goes through. The delay is inserted ...

I run an e-commerce website and we have various third-party JavaScript that add click handlers to links and forms and then insert a delay to make sure the tracking goes through. The delay is inserted ...

I'm trying to write a solution to a problem that requires three possible different return values depending on the result of two values. The possibilities are greater than, less than, or equal to. An ...

I'm trying to write a solution to a problem that requires three possible different return values depending on the result of two values. The possibilities are greater than, less than, or equal to. An ...

I want to build my website using Javascript for front end and PHP for backend. I want to know how can I keep header & footer same on all pages if I am using javascript for client side. I can do it ...

I want to build my website using Javascript for front end and PHP for backend. I want to know how can I keep header & footer same on all pages if I am using javascript for client side. I can do it ...

  1. freeze header footer
  2. keep header and footer on first page only
  3. keep header and footer on all pages in word
  4. keep header remove footer
  5. excel remove header keep footer
  6. word remove header keep footer

response is JSON Edge: sometimes inserts response property value into DOM briefly then removes it, sometimes logs error "SCRIPT5: access denied" (indicating CORS), response fully accessible from ...

response is JSON Edge: sometimes inserts response property value into DOM briefly then removes it, sometimes logs error "SCRIPT5: access denied" (indicating CORS), response fully accessible from ...

  1. xmlhttprequest access response