kunukn / react-slide-toggle

React component re-implementation for jQuery.slideToggle feature
MIT License
42 stars 7 forks source link

What if I want to slide components, which rendered by simple condition? #7

Closed WebKieth closed 5 years ago

WebKieth commented 5 years ago

Your readme example based on event + ref... khm, what if I just wrap it in a simple condition cause my logic based on it? Failed....

       let renderPassValidator = () => {
            if (!password.valid) {
                return <SlideToggle render={
                    () => {return <PassValidator matches={password.matches}/>}
                }/>
            }
        }

Without errors

kunukn commented 5 years ago

Hi,

It is possible to expand on mount. https://codesandbox.io/s/react-slide-toggle-czptc

For wrapping in a simple condition, then I have this simpler alternative. https://github.com/kunukn/react-collapse

I could probably to some bigger refactoring with react-slide-toggle with more flexible API and hooks support. I don't currently have the time for that.

I am spending my time on this version at the moment. https://github.com/kunukn/react-collapse

kunukn commented 5 years ago

I have updated to support outside toggle control using the toggleEvent prop.

example here. https://codesandbox.io/s/react-slide-toggle-controlled-toggle-9sqg0

kunukn commented 5 years ago

The readme has been updated with an example. https://github.com/kunukn/react-slide-toggle#toggle-state-from-outside-example