DEV Community

Discussion on: Build your first app with Mobx and React

Collapse
 
rosyshrestha profile image
Rosy Shrestha

Decorators are optional. I have mentioned the alternatives without decorators in the article.

And with the React 16.8 Hooks update, 'hooks let you use more of React’s features without classes'. And you can easily use Mobx with functional components ( no classes, no decorators ).

const person = observable({
  name: 'John Doe'
})

person.observe(...)
Enter fullscreen mode Exit fullscreen mode
// wrap the component in observer function from mobx-react package
const Function = observer(()) => {....}

// or use useObserver hook from mobx-react package
const Function = useObserver (()) => {....}

Enter fullscreen mode Exit fullscreen mode

For more details, you can read this section of mobx docs.