@
@
@Richswitch2018-11-12 15:46:23
JavaScript
@Richswitch, 2018-11-12 15:46:23

Disable buttons after updating redux store?

Hey!
I can't figure out how to disable the button individually when a new value comes from the redux store.
The button from the list should be disabled while loading data from the API, but when I write disable={loading} , the disable attribute is added to all buttons, and I need the attribute to be added only to the one that was pressed.
The code is like this:

...
  handleClick = () => {
// Запрос в  API
    this.props.fetch();
  };
...
  render() {
    const { loading } = this.props;
    return (
      <SubList d={visibility}>
        {list.map((data, i) => (
          <Button
            key={i.toString()}
            onClick={this.handleClick}
            disabled={loading}
          />
        ))}
      </SubList>
    );
  }

Here { loading } is a boolean value that comes from the redux store.
Assume that 10 buttons are rendered, how do I make it so that when I click on a specific button, the disable attribute is hung only on the button that I clicked.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Spirin, 2018-11-12
@rockon404

Obviously like this:

render() {
    return (
      <SubList d={visibility}>
        {list.map((item, i) => (
          <Button
            key={i.toString()}
            onClick={this.handleClick}
            disabled={item.isLoading}
          />
        ))}
      </SubList>
    );
  }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question