schovi / react-iscroll

React component for wrapping iScroll http://iscrolljs.com/
MIT License
236 stars 60 forks source link

How to update options? #32

Closed Benvorth closed 7 years ago

Benvorth commented 7 years ago

... after the react-iscroll was rendered on DOM? For example I want to disable scrollY under certain conditions and re-enable it later. Binding the options=... to a state variable didn't work...

schovi commented 7 years ago

@Benvorth react-iscroll should reinitialize iscroll itself when options changed. It was build with this feature in mind. Have to test it somehow.

schovi commented 7 years ago

@Benvorth Improved example file to show how to do it. https://github.com/schovi/react-iscroll/commit/d9601948b92d191b64f5ab35b26e268e70a9e477?diff=unified#diff-9dc42c58804e2841c5330a81a75b977bR77

Key is Object.assign({}, currentOptions, changedOptions). That mean, you have to create new object. Inside react-iscroll I do not compare each property separately, so If you just modify existing object it wont update component and wont refresh iscroll with new options.

I will take I look if I comparing can support changing of properties in options.