Reactjs functional component default props with props object

Viewed 157

In functional components we can pass props like this.

function Country(props){

}

and we can pass default props value like this

function Country({name:'Sri Lanka',description:'blah! blah!'}){
    
}

and then we can pass props like this to the component.

<Country name={'Germany'} description={'haha...'} />

But I do want to access props' history object. So I did

function Country({name:'Sri lanka',description:'haha',...props}){

}

but when I console.log props it is an empty object. In here I think I may want to pass the props object too. How do I do that?

<Country name={'Germany'} description={'haha...'} />
1 Answers

You just need to pass props when you use your Country component.

Like this:

<Country name={'Germany'} description={'haha...'} {...props} />
Related