1
votes

How can I have access to this.props in react but without render method? In a function method with const variable ? When I make console.log(this.props) I get an error.

const TopBar = ({ className, ...rest }) => { 
const classes = useStyles(); const [anchorEl, setAnchorEl] = React.useState(null); const open = Boolean(anchorEl); const [lan ,setLan] = React.useState('EN'); .... 

where should I place the props ??

2

2 Answers

2
votes

In a functional component you need to pass the props like this

const Component = (props) => {

    return <div>Component Content</div>

}

Then you can use it like this

console.log(props)
0
votes

In a function component, the first argument is the props.

const Example = (props) => {
  console.log(props);

  return null;
}