Me enfrento a un problema. mi aplicación reactjs tiene algunos elementos de tarjeta y tiene algunas descripciones aquí. Aquí quiero hacer una breve descripción y un botón, y cuando hago clic aquí, veo los detalles completos, y cuando hago clic por segunda vez, también se ocultará nuevamente, al igual que un botón de alternar para hacer una descripción corta y larga.
// Get a hook function const {useState} = React; const Example = ({title}) => { const [showMore, setShowMore] = useState(false); const text = "It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for lorein their infancy. Various versions have evolved over the years, sometimes by"; return ( <div className="App"> <p> {showMore ? text : `${text.substring(0, 50)}`} </p> <button className="btn" onClick={() => setShowMore(!showMore)}>Show more</button> </div> ); }; // Render it ReactDOM.render( <Example title="Example using Hooks:" />, document.getElementById("react") ); <script src="https://cdnjs.cloudflare.com/ajax/libs/react/17.0.1/umd/react.production.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/17.0.1/umd/react-dom.production.min.js"></script> <div id="react"></div>