Use Link State to Automatically Handle State Changes

Shane Osbourne
InstructorShane Osbourne

Share this video with your friends

Send Tweet

Storing and updating values inside a component’s local state (known as controlled components) is such a common pattern that Preact offers a really handy feature called ‘link state’ that not only removes the need to bind class methods, but also handles the setting of new values. This can remove the need for ‘setter’ style methods on classes and in this lesson we’ll look at an example of tracking the value of a ‘text input’

~ 3 years ago

Nice video - a small correction for the event and the binding of the scope. You can just do as such onInput={ e => this.setText(e) } - and you will stay in the lexical scope of the class.