S
S
SerjAndreev2019-08-13 17:06:28
JavaScript
SerjAndreev, 2019-08-13 17:06:28

How to check props?

const MainHeader = (props) => {
    let data = {};

    if (props){
        let data = this.props
    }
    else{
        data = {
            work: "",
            schedule: "",
            supportEmail: "",
            menu:[
                    {
                        url: '',
                        label: 'В кабинет',
                        target: '_self'
                    },
                    {
                        url: '',
                        label: 'Зарегистрироваться',
                        target: '_self'
                    }
                ]
        }
    }
    return (
        <header className="row store-header">
            <div className="col-md-12 store-header__top-info">
                <div className="row">
                    <div className="col-md-2"></div>
                    <div className="col-md-8">
                        <div className="row">
                            <div className="store-header__top-info-left-col col-md-8">
                                    <span className="store-header__work">
                                        Работаем: &nbsp; ПН-СБ <span>9.00-19.00</span>
                                    </span>
                                <span className="store-header__support">
                                        <a href="mailto:"></a>
                                    </span>
                            </div>
                            <div className="store-header__top-info-right-col col-md-4">
                                    <span>
                                        <NavLink to="/office">В кабинет</NavLink>
                                        &nbsp;или&nbsp;
                                        <NavLink to="/registration/register">Зарегистрироваться</NavLink>
                                    </span>
                            </div>
                        </div>
                    </div>
                    <div className="col-md-2"></div>
                </div>
            </div>
        </header>
    );
}

export default MainHeader;

How to check the props for emptiness and if so put your own object on the date ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yustas Alexu, 2019-08-13
@Yuxus

Install prop-types and follow instructions: https://ru.reactjs.org/docs/typechecking-with-prop...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question