gopinav / react-tutorials Goto Github PK
View Code? Open in Web Editor NEWSource code related to the YouTube tutorial series
Source code related to the YouTube tutorial series
Hi received this error with while npm start
refer attached text file for full log.
npm_start_error.txt
Facing a issue while throwing a new error in Hero.js file
I used
if(heroName === 'Joker')
{
throw new Error ('Not a Hero!')
}
but it does not throw the error it is showing blank screen
Thanks for the tutorial, I'm going through the vidoes and trying to learn Hooks with typescript.
How do I get rid of the below error? Would be great to know.
https://stackoverflow.com/questions/63855787/react-hook-tsx-and-untyped-array
HookCounter.tsx
import React from 'react'
import {useState} from 'react'
interface Props{}
interface Item{
id: number;
value: number;
}
interface Person{
firstName: string;
lastName: string;
}
const HookCounter : React.FC<Props> = () => {//S1 create functional component
//S3 : method capable of setting that state var
const initialCount = 0
const [count, setCount] = useState(0) // this hook accepts initial val, and returns current val, and
const [name, setName] = useState({firstName : '', lastName: ''}) // Ch 4: object in useState
const [items, setItems] = useState([]) // Ch 5: array in useState
const incrementFive = () =>{
setCount( prevCount => prevCount+5)
}
const addItem = () => {
setItems([ ...items, //copy prev array for merge
{
id: items.length
, value: Math.floor(Math.random()*10)+1
}//newitem
]) //setItems
}//addItem
return (
<div>
Ch 3: Using previous state: <em> setCount(prevCount => prevCount +1)</em>
Count : {count}<br/>
<button onClick={() => setCount(prevCount => prevCount +1)} > More + </button><br/>
{/* For incrementfive no ()=> */}
<button onClick={incrementFive} > More +5 </button><br/>
<button onClick={() => setCount(prevCount => prevCount -1)} > Less - </button><br/>
<button onClick={() => setCount(initialCount)} > Reset </button>
<hr/>
Ch 4: Using useState with object: <em>useState(json-object)</em><br/>
Manual merge with spread operator: <em>onChange= e = setName( ...name, firstName : e.target.value )</em>
<form>
{/* TODO check why should I mention both firstname and lastname in setname() */}
<input type="text" value={name.firstName} onChange={e => setName({ ...name, firstName : e.target.value })} /><br/>
<input type="text" value={name.lastName} onChange={e => setName({ ...name, lastName : e.target.value })} /><br/>
</form>
Your first name is: <em>{name.firstName}</em><br/>
Your last name is: <em>{name.lastName}</em><br/>
state variable name : {JSON.stringify(name)}
<hr/>
Ch 5: Using useState with arrays: <em>useState(json-object)</em><br/>
<button onClick={addItem}>Add a number</button>
<ul>
{items.map(item => (
<li key={item.id}> {item.value} </li>
))}//items
</ul>
</div>
);//return
};
export default HookCounter;
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.