All you need to know about the Context API | React Context API Crash Course

Sdílet
Vložit
  • čas přidán 27. 07. 2024
  • In this video I will go over the built in State Management solution for react. Context API is a very interesting api but it is constantly misused, so I wanted to go over my thoughts on it.
    Code: github.com/machadop1407/conte...
    Join our Discord: / discord
    🚀 Learn ReactJS By Building 6 Projects: codedamn.com/learn/reactjs-pr...
    🐙 GraphQL Course: codedamn.com/learn/graphql-fo...
    ► Buy Crypto on Coinbase: coinbase-consumer.sjv.io/PedroTech
    Social
    ▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
    Website: machadopedro.com
    Linkedin: / machadop1407
    Instagram: / _pedro.machado_
    Github: github.com/machadop1407
    Business Email: pedro@pedrotech.co
    Timestamps:
    00:00 | Intro
    01:11 | Why use the ContextAPI?
    05:48 | Creating a context
    07:00 | Creating a context provider
    10:32 | Best Practices - Creating context provider components
    13:25 | Drawback of ContextAPI
    Tags:
    - ReactJS Tutorial
    - ReactJS and MySQL
    - NodeJS Tutorial
    - API Tutorial
    #reactjs #contextapi
  • Věda a technologie

Komentáře • 95

  • @mostafa2199
    @mostafa2199 Před rokem +2

    Great video. I like how you didn't just explain how to implement context, but also revealed the drawbacks and mentioned where to use it.

  • @tadakuniyasuda8214
    @tadakuniyasuda8214 Před rokem +5

    Informational, straight to point, friendly, and motivational. I really like how you give us your honest opinion near the end based on your experience. It helps us learners because we are overwhelmed by so many things to learn from. Now I am going to watch your hooks video. Thank you again.

  • @byronk5
    @byronk5 Před rokem +3

    I really appreciate how balanced and informative this is . Great delivery and excellent content.

  • @ramosjeromedelrosario6103

    im really struggling to stop avoid unnecessary rerenders when using context api, you gave me the idea on how should i fixed it, thanks man

  • @jaimemedina3351
    @jaimemedina3351 Před rokem

    Good stuff here. I appreciate how the downside of context management is underscored. One really needs to think about state, but also the way the state changes.

  • @ChitruShrestha
    @ChitruShrestha Před rokem +7

    Thank you for taking the time to give drawbacks and opinions and your preferred method. It really made it easy to wrap around broad concepts.

  • @lasindunuwanga5292
    @lasindunuwanga5292 Před 2 lety +7

    Your knowledge was always incredible. Now your video graphics and etc. are also evolving... Great effort

  • @frankiefab
    @frankiefab Před 2 lety +1

    Thank you Pedro for this one. It came at the right time for me.

  • @matt112fly
    @matt112fly Před 2 lety

    perfect- i just wanted to look into the context API :) u helped me with redux so im looking forward to context api

  • @BoredBricks
    @BoredBricks Před 2 lety

    Good timing, I needed this.

  • @hassamulhaq7762
    @hassamulhaq7762 Před 2 lety +1

    Really informative content. I love your suggestions where and when.

  • @berndeveloper
    @berndeveloper Před rokem

    Love your video man, thanks so much for the info!

  • @Aziz-kw6ct
    @Aziz-kw6ct Před 3 měsíci

    This video is a lifesaver, thanks a bunch!

  • @geicianecosta3925
    @geicianecosta3925 Před rokem +1

    Voce eh incrivel!!! Adoro seus videos :D

  • @elwoseopenstepcrew1134

    i have the same feeling about redux and graphQL xd amazing video, subscribed ! great job

  • @songokussj4cz
    @songokussj4cz Před 2 lety +12

    Hi Pedro. Really nice, as always. I really liked your video on "4 types of Fetch" because you divided that into different files like it would be in production. Here at 8:20 you're saying "And obviously I'm doing it in one file. But imagine how it would look if you separate that to more files". Please: these people (myself partly included) which are watchich these beginner videos have almost certainly a problem to see how it would work with imports and so on in those separate files. So my tip for next time, show it in one file, no problem, but then, for 5 seconds (at the end for example) show it separated to more files with good file names and file structure. Nearly all internet tutorials, for "simplicity" are showing everything in one file.... Be different! Be closer to production! Like you were in "4 types of Fetch video" :-)

    • @sravyanandina
      @sravyanandina Před 2 lety +1

      Totally agree on this!!

    • @jaimemedina3351
      @jaimemedina3351 Před rokem

      Nonsense. The one file approach did a great job in showing the prop drilling tendency in React. Make your own videos before handing out 'tips'.

    • @chippandenga6722
      @chippandenga6722 Před rokem +4

      @@jaimemedina3351 😂Nothing wrong with suggestions. I am sure the creator appreciates the suggestion.

  • @heitormbonfim
    @heitormbonfim Před rokem +1

    Bruh, you're a life saver

  • @mdabidkalam3527
    @mdabidkalam3527 Před 11 měsíci

    I loved the way you explained.

  • @ytpeerz
    @ytpeerz Před rokem

    Thanks for the video, helped me understand the context API

  • @sriramr1981
    @sriramr1981 Před 10 měsíci

    Very Helpful. Thanks

  • @austinbriencabanada8229

    Thanks pedro .. really need this tutorial hope you make next.js typescript tutorial

  • @soumadip_skyy_banerjee
    @soumadip_skyy_banerjee Před rokem +1

    Love the content!

  • @nikolozmacharashvili1212

    Thank you for teaching me this stuff...

  • @cryptomallu6271
    @cryptomallu6271 Před rokem

    great video. thanks man

  • @misscarla_alhambra7345
    @misscarla_alhambra7345 Před 3 měsíci

    THANKS! Was very informative and helpfull

  • @nro337
    @nro337 Před 2 lety

    Thanks for this!

  • @alexdefaro
    @alexdefaro Před 2 lety

    Great video 👊

  • @francoischevalier9608

    You rock ! Thank so much

  • @ravisankar9122
    @ravisankar9122 Před 6 měsíci

    Excellent video.

  • @kevinemugisha9035
    @kevinemugisha9035 Před 8 měsíci

    This was helful!

  • @VijenderSingh-wr6fm
    @VijenderSingh-wr6fm Před 18 dny

    great video and explanation

  • @AhmedKhan-rt6oz
    @AhmedKhan-rt6oz Před rokem

    very well explained

  • @GabrielMartinez-ez9ue
    @GabrielMartinez-ez9ue Před 2 lety

    Great stuff as always. I pretty much use Zustand for everything these days.

  • @mohammadmahdialvansaz8001

    thanks. it helped alot

  • @anaselhassani2545
    @anaselhassani2545 Před rokem

    ty bruu

  • @friendshipwithjavascript

    Great Content

  • @devwithbrian1534
    @devwithbrian1534 Před 2 měsíci

    Thanks Pedro

  • @pemadechen9199
    @pemadechen9199 Před rokem

    Thank you :)

  • @saqibghouse
    @saqibghouse Před 2 lety +2

    Can you also make a video on best practices on react app file structure. and styling please

  • @AM-nm6ts
    @AM-nm6ts Před 2 lety

    thanks a lot 🙏🙏

  • @ThColinPereira
    @ThColinPereira Před 2 lety

    Amazing video

  • @discoverthecode2286
    @discoverthecode2286 Před 2 lety

    Thanks bro it heled me a lot. thanks a lot bro my sweet bro

  • @quelchx
    @quelchx Před 2 lety +4

    If you try to pass a null value into a createContext while you are using Typescript it will throw a warning. Yeah, you can change your tsconfig to ignore this (ignore null checks). There is a workaround, can't remember it at the moment -- but I figure I share this for the TS guys who might be watching this video while working LOL.

    • @PedroTechnologies
      @PedroTechnologies  Před 2 lety +2

      Yes! I use typescript at my job and on side projects, what I do is I create an object called `defaultValues` and also specify the format of the context with an interface

    • @quelchx
      @quelchx Před 2 lety

      @@PedroTechnologies Sounds about right. I have worked on some code bases were I think we did something like that with an initial state or like this (been a while) const authContext = useContext({} as AuthContextType) the context type being an ts interface or however we did it I forgets and am too lazy to go back and look =)

  • @fraternidadeaustriaca2625

    excelente video

  • @yasensim
    @yasensim Před 2 lety +2

    Thanks!

  • @kabagambedaniel2468
    @kabagambedaniel2468 Před 2 lety

    let me watch this one, i always learn a lot on this platform

  • @muhammedozalp
    @muhammedozalp Před 11 měsíci

    Thanks bro

  • @fabionunes2793
    @fabionunes2793 Před rokem +2

    A quick question: the re rendering is really a drawback the re rendering is a misunderstood feature of context?
    I mean, the name itself says, context. Is a thing to wrap components inside to warn these components, like: "hey, the state you want to show changed, so let's re render".

  • @autumndavis2638
    @autumndavis2638 Před 2 lety

    Hey Pedro! Thanks for the video. What VSCode theme are you using? I love it!

  • @willyhorizont8672
    @willyhorizont8672 Před rokem

    yo pedro, I create ContextProvider for socket io and use it for layout in react-router-dom element and use Outlet as a children inside that ContextProvider is that okay? previously I use builtin useOutletContext hooks provided by r-r-d but I have nested protected route so its throw and error.

  • @enriquesantosdeoliveira5798

    Olá Pedro! Vc tem conteúdos com typescript?

  • @bahibrahim101
    @bahibrahim101 Před rokem

    Thanks

  • @augischadiegils.5109
    @augischadiegils.5109 Před 2 lety

    ❤️❤️❤️

  • @YabombomTelevision
    @YabombomTelevision Před rokem

    Thats why i really like the vue team . They created pinia, and it has the solutions embeded in one solutions.

    • @aeiou...
      @aeiou... Před rokem

      Yeah. Hope pinia isn't tied to vue though

  • @nabinsaud4688
    @nabinsaud4688 Před 2 lety +2

    Hello bro please make complete FIREBASE REACT VIDEO INCLUDING ALL

  • @AminSani
    @AminSani Před rokem

    Could you please talk about RxJs or reactive state managment?

  • @papa_ethan
    @papa_ethan Před 2 měsíci

    You know you are just explaining to yourself, and do not mind that the viewer does not have the ideas of what you are saying so you should show what you are saying. Remember the point is you are here in order to be understood.

  • @skl949
    @skl949 Před 2 lety +1

    you are the next web dev simplified i swear

  • @krateskim4169
    @krateskim4169 Před rokem

    nice video

  • @AsifKhan-ee8ez
    @AsifKhan-ee8ez Před 2 lety

    When to use redux toolkit and when to use context api?

  • @chigbojames2803
    @chigbojames2803 Před 2 lety

    Do you have any video on react native?

  • @aeiou...
    @aeiou... Před rokem

    Im just getting back to react. Why not use redux for this kind of problems?

  • @slahomar1497
    @slahomar1497 Před 2 lety

    Could you make Relay tutorial please

  • @jordantanaliga100
    @jordantanaliga100 Před rokem

    Could you do typescript in react ?

  • @akaabdullah
    @akaabdullah Před 2 lety

    We need tutorial on REDUX with react

  • @albertoginelsalvador2172

    How do you install it?

  • @chethananderson3446
    @chethananderson3446 Před rokem

    the changes made to this context object does'nt re-render the child components , you're passing the setUsername as a reference to the value prop, the reason why it is re-rendering is , you're making changes to the state by passing its setUsername reference and offcourse if a state in parent component changes the child component is re-rendered. Context API changes doesnt re-render it's child components.

  • @akaabdullah
    @akaabdullah Před 2 lety +1

    well i understand what you tried to tell so now please make a tutorial on REDUX

    • @Savics_dev
      @Savics_dev Před rokem

      He already has a tutorial on redux... well detailed

  • @AM-nm6ts
    @AM-nm6ts Před 2 lety +1

    if I use several providers. where I should put them please. like this?
    thanks a lot

    • @PedroTechnologies
      @PedroTechnologies  Před 2 lety +1

      You can put them where ever you want! You could do it like this if you want to access all the data from each provider everywhere in the app. But you can also put providers inside of the app so that the data is only accessible inside of a group of components

    • @AM-nm6ts
      @AM-nm6ts Před 2 lety

      @@PedroTechnologies thank you so much :) god bless you 🙏🙏

  • @filipevalentegomes2383
    @filipevalentegomes2383 Před 2 lety +2

    Wrapping multiple components with context will turn into a big mess the bigger the app gets. It’s good to know, but I would never use it, there are just too many better options.

    • @PedroTechnologies
      @PedroTechnologies  Před 2 lety +1

      I agree! Thats why i try to use React query + composition in most cases. And use the context api for general states that are rarely mutated.

  • @1989SeanSmith
    @1989SeanSmith Před rokem

    Could you add the starting code also, so that we can follow along from the beginning?

    • @theintrovert894
      @theintrovert894 Před rokem

      i am terribly confused why he call child compoenet if he can directly call grandchild

  • @oncoding4520
    @oncoding4520 Před rokem

    So I planned to watch the video on the series of your react tutorials but this on is more longer so im going to start with these. I wanted to give you a gift but dont know how to contact you

  • @nomapos
    @nomapos Před 2 lety +1

    React native !!!!!!!!!!!!!!!!!!

  • @anjalichauhan6347
    @anjalichauhan6347 Před rokem

    what are children and why are they passed as props

  • @tarek_maza
    @tarek_maza Před rokem

    Badly explained

  • @RohitKumar-ht4sr
    @RohitKumar-ht4sr Před 2 lety

    Download SUBSGAIN App from play store

  • @grazielak.pauselius4225

    Thank you, Pedro! The way you explain makes everything super easy! Go Brazil 🟢🟡🔵