With https://material-ui.com/components/popper/ React, material-ui,
I want to show the Popper just after the page loaded, without clicking on the button.
import React from 'react'
import Popper from '@material-ui/core/Popper'
import Typography from '@material-ui/core/Typography'
import Button from '@material-ui/core/Button'
import Fade from '@material-ui/core/Fade'
import Paper from '@material-ui/core/Paper'
export default function PositionedPopper() {
const elRef = React.useRef(null)
return (
<div>
<Popper open={true} anchorEl={elRef.current} placement={'left'} transition>
{({ TransitionProps }) => (
<Fade {...TransitionProps} timeout={350}>
<Paper>
<Typography>The content of the Popper.</Typography>
</Paper>
</Fade>
)}
</Popper>
<Button ref={elRef}>left</Button>
</div>
)
}
This code shows the popper on the top left on the screen because onInit, anchorEl is Null
How can we set anchorEl when the component loads the first time?