route render props code example

Example 1: route component with props

<Route
  path='/dashboard'
  component={() => <Dashboard isAuthed={true} />}
/>

Example 2: render props

//Render props are functions that are passed to props as values
const User = (props) => {
	const [name, setName] = useState('John')

	//we pass values to prop-function as args
	return <div>{props.render(name)}</div>
}

//Then we can use this component like this:
<div>
  //when using the component we receive the passed values (name) as args here 
  <User render={(name) => <div>{name}</div>} /> 
</div>

Example 3: react route props

<Route
          path="/page"
          render={() => (
            <Page
            //pass the props through the route
              username={username}
              password={password}
              email={email}
            />
          )}
          exact={true}
        />