Reacting
Reacting

Reputation: 6133

Can't any data from a checkbox

I am using Carbon Design System and the checkbox component from it. With a console.log all I get is true when the checkbox is checked and false when it's not.

I am doing this:

const onChange = event => {
  console.log(event);
};

And this on the render method:

{CheckboxItems(t).map(item => (
  <ToolbarOption key={item.id}>
    <Checkbox key={item.id} id={item.id} labelText={item.labelText} value= 
    {item.value} onChange={onChange} />
  </ToolbarOption>
))}

If you see the URL I posted above, there is a tab named Action Logger where you can see the data. But I can't get that same log on my app.

Any ideas?

Upvotes: 0

Views: 41

Answers (1)

Agney
Agney

Reputation: 19234

From the documentation, the onChange function provides three props being in the order: value id event

So to get the same output as the action logger, you have to refractor the onChange function to:

onChange = (value, id, event) => {
  console.log({value, id, event})
}

Upvotes: 1

Related Questions