Coder Social home page Coder Social logo

react-tutorials's People

Contributors

gopinav avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-tutorials's Issues

Issue while implementing Error Boundaries

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

HookCounter - tsx & untyped array issue

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

image

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;

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.