Skip to content

Instantly share code, notes, and snippets.

@ngohungphuc
Created August 2, 2019 08:38
Show Gist options
  • Select an option

  • Save ngohungphuc/fdbff75c1b364863577ae1221d3034fa to your computer and use it in GitHub Desktop.

Select an option

Save ngohungphuc/fdbff75c1b364863577ae1221d3034fa to your computer and use it in GitHub Desktop.
function Example({text, maxLength}) {
// define hidden state default init value is true and
// setHidden function to update state
const [hidden, setHidden] = useState(true);
// on click we change the state of hidden and trigger re-render of the view
return (
<span>
{hidden ? (
<a onClick={() => setHidden(false)}> read more</a>
) : (
<a onClick={() => setHidden(true)}> read less</a>
)}
</span>
);
}
export default Example;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment