React-sortable-hoc: Using controlled components inside SortableElement

Created on 13 Feb 2017  ·  1Comment  ·  Source: clauderic/react-sortable-hoc

Hi

I need to have a text input inside the SortableElement and it has to be controlled so that I can change its value, and a value of another item changes based on that, but apparently since this plugin uses HOC I can not have states inside SortableElement.

Is there any way around this? (using defaultValue on the text input does not work in my case)

Most helpful comment

Sure, you can absolutely use state.

Here's a basic example:

class MyElement extends Component {
  state = {
    value: 'Test'
  }
  render() {
    return <input value={this.state.value} onChange={(e) => this.setState({value: e.target.value})} />;
  }
}

const SortableMyElement = SortableElement(MyElement);

>All comments

Sure, you can absolutely use state.

Here's a basic example:

class MyElement extends Component {
  state = {
    value: 'Test'
  }
  render() {
    return <input value={this.state.value} onChange={(e) => this.setState({value: e.target.value})} />;
  }
}

const SortableMyElement = SortableElement(MyElement);
Was this page helpful?
0 / 5 - 0 ratings

Related issues

ricokahler picture ricokahler  ·  3Comments

ianmstew picture ianmstew  ·  3Comments

ncammarata picture ncammarata  ·  4Comments

dlee picture dlee  ·  4Comments

zhujunwei picture zhujunwei  ·  3Comments