FlareStart
HomeNewsHow ToSources
FlareStart

Where developers start their day. All the tech news & tutorials that matter, in one place.

Quick Links

  • Home
  • News
  • Tutorials
  • Sources
  • Privacy Policy

Connect

© 2026 FlareStart. All rights reserved.

Back to articles
ReactJS SOLID Principle ~LSP (Liskov Substitution Principle)~
NewsWeb Development

ReactJS SOLID Principle ~LSP (Liskov Substitution Principle)~

via Dev.to WebdevOgasawara Kakeru3h ago

・In React, LSP indicates that when you expand the base component or HTML, you should not break base functionality. Bad code // You can not use the normal button const CustomButton = ({ label }: { label : string }) => { return < button > { label } </ button >; }; // The onClick is ignored if you pass. And type is an error. < CustomButton label = "preserve" onClick = { () => alert ( ' Preserved ' ) } /> Good code You should extend all attributes of the button and pass it. import { ComponentPropsWithoutRef } from ' react ' ; //Define the type to receive all of the attributes interface ButtonProps extends ComponentPropsWithoutRef < ' button ' > { variant ?: ' primary ' | ' secondary ' ; } const CustomButton = ({ variant , children , ... rest }: ButtonProps ) => { const style = variant === ' primary ' ? { backgroundColor : ' blue ' } : {}; // pass all of the attributes such as onClick or type by `...rest` return ( < button style = { style } { ... rest } > { children } </ button > ); }; < Cu

Continue reading on Dev.to Webdev

Opens in a new tab

Read Full Article
0 views

Related Articles

One Way or Another, Most of Our Electricity Comes From Solar Power
News

One Way or Another, Most of Our Electricity Comes From Solar Power

Wired • 23m ago

The most useful command in the age of agentic
News

The most useful command in the age of agentic

Dev.to • 38m ago

️ The 5IR Hardware Patch: The Syntropic Processor
News

️ The 5IR Hardware Patch: The Syntropic Processor

Medium Programming • 43m ago

These 5 Amazon Spring Sale deals are HSA and FSA eligible
News

These 5 Amazon Spring Sale deals are HSA and FSA eligible

ZDNet • 52m ago

Rank the 50 best Apple products
News

Rank the 50 best Apple products

The Verge • 1h ago

Discover More Articles