-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Maria:component-based-design, 3 weeks #420
Comments
Week 1/ Week 2 I pushed my progress here I Need Help With:What "root" element is? What went well?I am getting familiar with React slowly but surely. I formed a big picture of:
I've also tried:
What went less well?Splitting components and re-render cycles (all children). I think three weeks are not enough for this module, at least for me. Lessons LearnedPutting state at lower levels is efficient Sunday Prep WorkKeep working on to-do list improvements. |
Week 3
I Need Help With:When I store all input values in a local state (at the form level) and then I want to use this data in order to create a new user in my data base, how can I pass the data to useEffect? Example: FORM component:import React, { useState } from 'react'
export default function Form({onSubmit }) {
const [person, setPerson] = useState({
username: "",
email: "",
password: ""})
return (
<form
onSubmit={(e) => {
e.preventDefault();
onSubmit(person);
}}
className="w-25"
style={{ margin: "auto" }}
>
<div className="mb-3 mt-3">
<label htmlFor="username" className="form-label">
Username
</label>
<input
type="text"
value={person.username}
onChange={(e) => {
setPerson({
...person,
username: e.target.value,
});
}}
className="form-control"
id="username"
aria-describedby="emailHelp"
required
></input>
</div>
...
...
<button
type="submit"
className="btn btn-outline-primary"
>
Sign up
</button>
</form> APP parent :import { useEffect, useState } from "react";
import Form from "./components/Form.js";
const App = () => {
...
...
const handleSubmit = (person) => {
console.log(person)
}
//I have props from form component with all inputs (person.username, person.email..)
//How can I apply useEffect(()=>{fetch..},[]) as to send a post query when Person varable is changed.
// It doesn't work if I put Person inside useEffect
useEffect(() => {
fetch("http://localhost:1337/api/auth/local/register", {
method: "POST",
headers: {
"Content-Type": "application/json",
// 'Content-Type': 'application/x-www-form-urlencoded',
},
body: JSON.stringify({
person.username: account.username,
person.email: account.email,
person.password:account.password
}),
})
.then((e) => e.json())
.then((response) => {
console.log(response);
const data = response;
setNewUser(data);
})
}, [ person??])
return (
<div className="container-fluid">
...
<Form open={openForm} activeForm={activeForm} onSubmit={handleSubmit} />
...
</div>
);
}
export default App; What went well?I am able to use hooks, props, separate components from a parent and pass data among them. What went less well?Even when I start with small and clear steps my code gets messy soon.. Lessons LearnedA component with some local state is “uncontrolled”. Sunday Prep WorkStill fighting with my chat-app |
Component-Based Design
Learn to design, plan and build frontend applications using a Component-Based approach. You will explore the React library which is designed to make Component-Based design easy and efficient.
Learning Objectives
Priorities: 🥚, 🐣, 🐥, 🐔 (click to learn more)
There is a lot to learn in this repository. If you can't master all the material
at once, that's expected! Anything you don't master now will always be waiting
for you to review when you need it. These 4 emoji's will help you prioritize
your study time and to measure your progress:
need for this module and the next. You do not need to finish all of them but
should feel comfortable that you could with enough time.
all if you just had more time. It may not be easy for you but with effort you
can make it through.
You should have a big-picture understanding of these concepts/skills, but may
not be confident completing the exercises.
If you are finished with 🥚, 🐣 and 🐥 you can use the 🐔 exercises to push
yourself without getting distracted from the module's main objectives.
1. Rendering Static Pages
🥚 JSX : you can ...
2. Rendering Data
🥚functional React components: you can ...
Create a React function component (both function definition and arrow function styles)
Import/export components between files
🥚 Render data: you can
.map
method🥚 Components and props : you can ...
🥚 Create reusable components: you can ...
3. Stateful Components
useState
useEffect
(any side-effect)🥚VDOM : you ....
🥚 Hook
🥚
use-state
🥚
use-effect
🥚 component lifecycle
4. Events
5. Component Structure
6. Consuming APIs
useEffect
callbacks7. Frontend Routing
8. Global State
useContext
useContext
useState
The text was updated successfully, but these errors were encountered: