Skip to main content

Command Palette

Search for a command to run...

how to provide a fallback for an html element in React?

Published
1 min readView as Markdown
how to provide a fallback for an html element in React?

In case that "type" should not set we add the or operator , the alternative is 'button' . So if props.type is undefined this 'button' value will be used as a fallback type for the built in button.

import React from 'react';
import classes from './Button.module.css';

const Button = (props) => {
    return (
        <button className={classes.button}   type={props.type || 'button' } >

            {props.children}

        </button>
    );
}

export default Button;

More from this blog

Omar's blog

135 posts