loading...
markdown guide
 

Okay, there are two problems with your code.

The first one is here:

handleAddToolbox = (alat) => {
    this.setState({
      toolbox: [
        ...this.state.toolbox,
        this.alat
      ]
    });
  };

Specifically the line this.alat. You're trying to add something called this.alat to this.state.toolbox, but your class doesn't have this property. In fact, want you want to do is to add the argument passed to handleAddToolbar. So you should remove this:

handleAddToolbox = (alat) => {
    this.setState({
      toolbox: [
        ...this.state.toolbox,
        alat
      ]
    });
  };

The second problem is in the render method. Specifically here:

<ul>
  {alati.map((alat) => (
    <li onClick={this.handleAddToolbox}>{alat}</li>
  ))}
</ul>

You're passing the method handleAddToolbox to the event listener but you're not giving it any argument. So when you click on the element, no argument gets passed. What you should do is create a function that passes the argument you want. Something like this:

<ul>
  {alati.map((alat) => (
    <li onClick={() => this.handleAddToolbox(alat)}>{alat}</li>
  ))}
</ul>
 

Hey! Thank you very much, I have been struggling with this for quite some time, and this works perfectly! :) By the way, how do you quote code so it appears in a box?

 

You're welcome^

There are two ways to quote code.
For inline code, you can use single back-ticks. Like this:

The word `this` will be styled as code.

For a block of code, it's the same but with three back-ticks. And if you want it to highlight its syntax according to a particular language, you can specify it after the back-ticks:



```
This will be a code block
```




```javascript
This will be a code block highlighted as JavaScript
```


You can find more info about the markdown in the cheatsheet

Classic DEV Post from Nov 21 '19

What are your favourite Alfred workflows?

PDavor profile image

dev.to now has dark theme. 🌝

Go to the "misc" section of your settings and select night theme

(You can also change font to sans serif, which a lot of folks prefer.) 💖