The ability to reply to discussions is limited to PRO members. Want to join in the discussion? Click here to subscribe now.

Static Methods in React

Static Methods in React

2:11
The statics object of our React view components is meant to contain values or functions that can be accessed at any time without needing an instance of that component created.
Watch this lesson now
Avatar
egghead.io

The statics object of our components is meant to contain values or functions that can be accessed at any time without needing an instance of that component created.

Avatar
Deryck

Can someone please explain to me the benefit of this? Besides adding another layer of abstraction to calling add(), I can't see this being any different than defining function add(x, y) { ... } somewhere outside of that React component.

However, It is pretty late, so I may just be missing something blatantly obvious.

In reply to egghead.io
Avatar
Joseph

This is a pretty simple example. Have a look at the source code for react-router (https://github.com/rackt/react-router), react-bootstrap (https://github.com/react-bootstrap), or react-dnd (https://github.com/gaearon/react-dnd) for more advanced usage. I'll be revisiting statics in a later lesson.

In reply to Deryck
Avatar
dave

Thanks but....Just a quick example for real life usage would be appreciated. The source code you point us to is quite advanced and requires quite a bit of effort to actually find use of static. Or specify which lesson expands on the topic please

In reply to Joseph
Avatar
Joseph

In react-router willTransitionTo is a static method we can use to interrupt a transition as needed.

In reply to dave
HEY, QUICK QUESTION!
Joel's Head
Why are we asking?