From 4cdc910d9759145c9c895884ef7dbbebc08216bc Mon Sep 17 00:00:00 2001 From: Maria Date: Thu, 9 Feb 2023 00:10:41 +0000 Subject: [PATCH] update class component --- examples/react-concepts/src/App.css | 2 +- examples/react-concepts/src/App.js | 18 +++++--- .../src/components/class/Input.jsx | 43 +++++++++++++++---- 3 files changed, 47 insertions(+), 16 deletions(-) diff --git a/examples/react-concepts/src/App.css b/examples/react-concepts/src/App.css index e550032..a75369a 100644 --- a/examples/react-concepts/src/App.css +++ b/examples/react-concepts/src/App.css @@ -1,5 +1,5 @@ .App { background-color: bisque; min-height: 100vh; - font-size: 1.5rem; + font-size: 1rem; } diff --git a/examples/react-concepts/src/App.js b/examples/react-concepts/src/App.js index 586cc28..01c5339 100644 --- a/examples/react-concepts/src/App.js +++ b/examples/react-concepts/src/App.js @@ -1,11 +1,12 @@ import React, { useState } from "react"; + import Input from "./components/class/Input"; + import "./App.css"; function App() { - const [state, setState] = useState("default"); - - + const [text, setText] = useState("default"); + const [name, setName] = useState("default"); return (
- - - -

{state}

+ Text: +
+ Nombre: + {/*Apellido: + Edad: */} +

Text: {text}

+

Nombre: {name}

); } diff --git a/examples/react-concepts/src/components/class/Input.jsx b/examples/react-concepts/src/components/class/Input.jsx index 7993700..a97a97d 100644 --- a/examples/react-concepts/src/components/class/Input.jsx +++ b/examples/react-concepts/src/components/class/Input.jsx @@ -1,17 +1,44 @@ import React, { Component } from "react"; class Input extends Component { - constructor() {} - //state = "default"; + constructor(props) { + super(props); + this.state = { value: "", counter: 1 }; + this.handleChange = this.handleChange.bind(this); + } + + handleChange(event) { + //Actualizae estado de + this.setState((state, props) => { + return { ...state, value: event.target.value }; + }); - /*function handleChange(event) { - console.log(event.target.value); - //setState(event.target.value); - //console.log("state", state); - }*/ + this.props.setValue(event.target.value); + } + + componentDidMount() { + console.log( + "Ya se renderizó el componente!! -- Hacer llamado se side effects (APIS)" + ); + } + + componentDidUpdate(prevProps, prevState, snapshot) { + console.log("componentDidUpdate", prevProps, prevState, snapshot); + } + + componentWillUnmount() { + console.log("componentWillUnmount..."); + } render() { - return ; + return ( + + ); } }