A presentation at RuhrJS in in Bochum, Germany by Jenn Creighton
THE HOW AND WHY The how and why of flexible OF FLEXIBLE REACT React components COMPONENTS
Hi! I’m Jenn. Senior Frontend Engineer, ClassPass @gurlcode
@gurlcode
flexible @gurlcode
@gurlcode
@gurlcode
with Tooltip withTooltip @gurlcode
withDot with Dot with Tooltip withTooltip @gurlcode
with Modal withModal withDot with Dot with Tooltip withTooltip @gurlcode
<BlockComponent <BlockComponent className=“block block—md block—orange” className=“block block-md block—orange” withTooltip={false} message={message} withDot={false} withTooltip={false} withModal withModal modalProps={modalProps} modalProps={modalProps} userId={userId} onModalClose={onModalClose} userName={userName} withDot={false} onMouseOver={onMouseOver} experimentRunning experimentId={experimentId} withExperiment colorChange={false} experimentId={experimentId} showMessageOnLoad onModalClose={() => {}} userName={userName} hasRoundedCorners userId={userId} withAnalytics analyticsProps={analyticsProps} analyticsProps={analyticsProps} /> roundedCorners /> BEWARE THE APROPSCALYPSE @gurlcode
@gurlcode
@gurlcode
You have another reservation at this time. @gurlcode
Is the user logged in? yes no State of subscription? unsubscribed Join cancelled Reactivate subscribed Join State of class? available unavailable reserved Reserve Disabled Cancel @gurlcode
@gurlcode
reusable !== flexible @gurlcode
Flexibility is about more than reusability. It’s about the ability understand and augment. @gurlcode
@gurlcode
@gurlcode
@gurlcode
@gurlcode
@gurlcode
@gurlcode
Keep business logic out of your components. @gurlcode
@gurlcode
Centralized logic is easier to reason about @gurlcode
Test the component separate from the logic @gurlcode
@gurlcode
@gurlcode
@gurlcode
@gurlcode
@gurlcode
@gurlcode
@gurlcode
@gurlcode
@gurlcode
@gurlcode
@gurlcode
components[type] @gurlcode
components = { reserve: ReserveCta, join: JoinCta, cancel: CancelCta, disable: DisableCta, reactivate: ReactivateCta } @gurlcode
const Component = components[type]; @gurlcode
const Component =${left || right}Sidebar
;
@gurlcode
const Component = props.isCard ? ( <Card> <Content /> </Card> ) : (<Content />); @gurlcode
@gurlcode
@gurlcode
@gurlcode
@gurlcode
@gurlcode
@gurlcode
Decreased prop complexity Use whatever logic we want Use whatever logic we want Use individual CTAs alone Use&individual CTAswith alone Add remove CTAs ease Add & remove CTAs with ease @gurlcode
CTAs added and removed for A/B tests Removing Disable CTA on some pages Classnames changed Messaging changed for ReserveCta Ask for specific CTA on specific page @gurlcode
Hmm… @gurlcode
Render Props* *children as a function @gurlcode
… so what if children were a function? @gurlcode
@gurlcode
?? ? ? ? ? ? ?? ? ? ? ? ? ?? ? ? ? ?? ? ? ? ? ? ? ? ? ?? @gurlcode
@gurlcode
@gurlcode
@gurlcode
@gurlcode
@gurlcode
@gurlcode
Render Props === state delegate children function === UI handler @gurlcode
https://reactjs.org/docs/render-props.html https://github.com/paypal/downshift @gurlcode
@gurlcode
you === flexible @gurlcode
@gurlcode
Know your traps. @gurlcode
Kill your darlings. @gurlcode
Start with the ideal API Let the API inform the component design Decide what level of magic you want Business logic does not belong in components Render Props is awesome (use it!) Be flexible as an engineer (know your traps, kill your darlings) @gurlcode
Thank you! Content by Jenn Creighton Illustrations by Janny Ji (jannyji.com) @gurlcode
Here’s what was said about this presentation on social media.
I’ve been meaning to tell you that I made my whole team at work watch your talk from @RuhrJS in our monthly movie-watching session. Apropscalypse has entered our common vocabulary, and it has influenced how we’ve built components since. Thank you 💕
— Michelle 💅 (@msmichellegar) December 16, 2018
@gurlcode this is such a great talk! So many good points, a lot of which apply to other frameworks. I've been learning similar things recently so this provides a lot of great insight for where I am at right now.https://t.co/pMZzxMF4RF
— Hayden Braxton (@hayden_dev) December 12, 2018
Wow, @gurlcode is killing at her talk about how to make UI components more flexible. She made a good case of separating flexibility from reusability as the two aren’t equal #fstoco @fullstackTO pic.twitter.com/SSLhbHGdTt
— Sergio Cruz (@hashtagserg) November 29, 2018
Really excellent talk by @gurlcode at #fstoco. Words of wisdom, "As engineers, we need to know our traps."
— J R Mykolyn (@JRMykolyn) November 29, 2018
Really enjoyed @gurlcode ‘s talk on creating flexible React components; learning to “kill your darlings”. 👏 pic.twitter.com/XdHHMF2aJM
— Alberto Leal 🎊 (@dasheddashed) November 29, 2018
Absolutely legendary presentation on Flexible Components from @gurlcode in progress rn pic.twitter.com/qbJW74agRD
— Matt Clough (@cluffpost) November 2, 2018
@gurlcode gives a mean React talk
— Meggie (@meggie_l) November 2, 2018
Learning how to fight the aPROPScalypse😱 in the React components @gurlcode #ruhrjs18 #reactjs pic.twitter.com/Kpd0e21d4c
— David Kopal (@coding_lawyer) October 14, 2018
Awesome talk about flexible #ReactJS components by @gurlcode 🤩 Step by step refactoring of a relatable rl example. Really helpful and hands on! ❤️ #apropscalypse #ruhrjs18 pic.twitter.com/WosguilAaW
— Mirjam Bäuerlein (@mirjam_diala) October 14, 2018