Initially I setted the text as list in use-state and it change to grid when I click on it.How to show the list again when I click?
const [buttonText, setButtonText] = useState('List');
function handleClick() {
setButtonText('Grid');
};
This is the use-state and the function that changes the text.Can anyone help me ?
CodePudding user response:
You can call same method and use ternary operator (check your current state and setState according to it).
function handleClick() {
setButtonText(buttonText == 'Grid' ? 'List' : 'Grid');
};