Search⌘ K

What is the Prop Getters Pattern?

Explore the Prop Getters Pattern to improve how you manage and customize props in React components with hooks. Understand the difference between traditional props collection and using functions that return props, enabling reusable and adaptable component design.

Props Collection vs. Prop Getters Pattern

In JavaScript, all functions are objects. However, functions are built to be more customizable and reusable.

Consider the following:

Javascript (babel-node)
const obj = {name: "React hooks"}
console.log(obj)

If you wanted to create the same object but allow for some level of customization, you could do this:

Javascript (babel-node)
const objCreator = n => ({name:n})

Now, this ...