Javascript scope is strictly function based. Once a variable is not in your scope it is impossible for you to access it. Therefore you need to make the variable part of your scope:
export default function TrackPage(props) {
const classes = useStyles();
var playlist; // Make this variable available to both
// useEffect and handleToolBarClick
useEffect(() => {
playlist = 1;
},[]);
function handleToolBarClick(){
playlist // this works
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…