DEV Community

Discussion on: React design patterns (part 2)

Collapse
 
canastro profile image
Ricardo Canastro
Option.Blue = function (props) {
  props.style.backgroundColor = "blue";
  return Option(props);
};
Enter fullscreen mode Exit fullscreen mode

You shouldn't mutate an argument that is passed as reference. It's safer to create a copy and change the color there.

return Option({ 
  ...props, 
  style: { ...props.style, backgroundColor: 'blue' } 
});
Enter fullscreen mode Exit fullscreen mode
Collapse
 
tomeraitz profile image
Tomer Raitz

Thank you for your input. It's a very important point. You are probably right, but I'm not sure because as I studied this pattern, I saw that the way I wrote it was the conventional way to write it. Still, it's a really good point, thank you!