Improve how you style and compose React apps — Use components in defaultProps

Theming guidelines — Part 5 — How to solve the problem with components with a large number of props

Marcel Mokos
Jan 18, 2019 · 5 min read
Image for post
Image for post
function withDefaultObjectParamemeterAndDestructuring({
a = 1,
b = 2,
} = {}) {
console.log(`a=${a}, b=${b}`);
}
withDefaultObjectParamemeterAndDestructuring({b: 5}); // "a=1, b=5"

📚 Define some vocabulary

React.Component

Problem with components with a large number of props

The Solution

Why are defaultProps better than default function parameters

const Component = ({a = 1}) => {}
Component.defaultProps = {b: 2}
Component.a // Error // variable "a" is not accesible
Component.defaultProps.b // 2

Render props or Function as Child pattern

The simplest example of render props
Image for post
Image for post
React you know

Do not use standard CSS for React Components

The Next Generation of CSS-in-JS

Image for post
Image for post
Emotion logo

Using a presentational component in defaultProps of presentational containers

ableneo Technology

Application Development, Data Science, Experience Platforms

Marcel Mokos

Written by

I'm fanatic to next generation Javascript lambda, yield, async/await everything. I admire typescript and flow types. Javascript will ultimately rule the world.

ableneo Technology

Application Development, Data Science, Experience Platforms

Marcel Mokos

Written by

I'm fanatic to next generation Javascript lambda, yield, async/await everything. I admire typescript and flow types. Javascript will ultimately rule the world.

ableneo Technology

Application Development, Data Science, Experience Platforms

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store