DEV Community

JonathanSum
JonathanSum

Posted on

how to convert this to hook?(this.setstate, call back)

https://github.com/mochixuan/react-native-drag-sort

ref={this.sortableViewRef}
dataSource={items}
keyExtractor={(item) => item.text} // 1、isRequired
renderItem={this._renderItem}
onDataChange={(data, callback)=> {
this.setState({items: data},()=>{
callback() // isRequired
})
}}
/>

In on Data change, you can see it uses setState and call back. I don't think useEffect can work here.

https://github.com/mochixuan/react-native-drag-sort

Top comments (1)

Collapse
 
_bkeren profile image
'' • Edited

const [items,setItems] = useState([])

useEffect(() => callback(), [items])

onDataChange={(data)=> {
setItems(data)
}}