by juanger · 10y ago · 0 comments
The beauty of "stateless" components is that you can see them as functions, and should aim to create them as pure functions[1] where the only thing that can change the output (HTML) of your component/function is its input.
Another way to see it is as syntactic sugar for pure functions where instead of:
MyMenu.render({name: 'Something', open: false});
MyMenu.render({name: 'Something', open: true});
You have
var menu = new MyMenu({name: 'Something', open: false});
menu.render();
// Then change the state:
menu.setOpen(true);
menu.render();
// Or maybe
menu.open(); // which calls setOpen and render
No comments yet.