React Modal Tutorial Using Hooks and Styled Components

แชร์
ฝัง
  • เผยแพร่เมื่อ 7 ก.ย. 2024

ความคิดเห็น • 133

  • @joza5422
    @joza5422 2 ปีที่แล้ว +2

    2 days... i tell you 2 days I was trying to figure out how to do this and this solved my problem thank you Brian fr fr you're the truth

    • @Azertex
      @Azertex 2 ปีที่แล้ว

      me too...

  • @rachelperkins5874
    @rachelperkins5874 3 ปีที่แล้ว +12

    I'm only 5 months into coding and 1 month into building in React and I was able to create a modal thanks to you! Never knew you could create styled components like that! All my CSS lives on css files. I'm going to attempt writing it on the component itself on my next project! Your code looks so clean!

    • @bgeorgiev87
      @bgeorgiev87 3 ปีที่แล้ว

      Having in mind that this is posted 4 months ago ... my advice to anyone who reads this comment is that 5 months of coding are not nearly enough to start with a framework, unless you are some sort of genious. Most ppl wouldn't even understand the main concepts of JS (or programming in general) that early in their career. Take it slow, learn core JS ES6 syntax and after that go ahead with your first library. Otherwise I highly doubt you'll be able to even understand what is what.
      In general this is a really missleading comment for any rookie, but that's just my opinion.
      Other than that - nice tutorial :) Thank you!
      All the best

    • @rachelperkins5874
      @rachelperkins5874 3 ปีที่แล้ว +3

      @@bgeorgiev87 Started on freecodecamp end of September (granted i built static html css sites in high school for funsies). Opened a GitHub account September 23, first commit January 6, hired as a full time front end engineer contractor April 1, switched to full time software engineer employee for the company June 1. So yes, it can be done.
      Almost all my work is react and, yes, I cried, multiple times. But if you literally quit your job to spend months coding, you can become a front end/full stack engineer. I also live with an engineer, dropped a pretty penny on a bootcamp, have a masters in teaching, and taught math. So yeah, lots of advantages. But it can be done! Don’t give up!

    • @ozzyfromspace
      @ozzyfromspace 3 ปีที่แล้ว

      @@rachelperkins5874 congratulations! You're my inspiration. I started my job search a few days ago (ironically also a trained engineer/mathematician, specialized in the spectral analysis of pdes, particularly numerical methods using Fourier and Laplace analysis to study hyperbolic systems). Hoping to get my first web-dev job before years end.

    • @rachelperkins5874
      @rachelperkins5874 3 ปีที่แล้ว

      You can do it! At this stage, you should be doing 1-2 interview problems (LeetCode), studying up data structures, and searching for opportunities (either cold or in your network) daily! Hope you have a cool project or two deployed! Best of luck! It can be done!

    • @LarsRyeJeppesen
      @LarsRyeJeppesen 2 ปีที่แล้ว

      React is great for super beginners. Less so for experienced ...

  • @ikmalshahzan2480
    @ikmalshahzan2480 3 ปีที่แล้ว +4

    Thanks brian ! I really need this on my project

  • @earthycoin
    @earthycoin 3 ปีที่แล้ว +5

    Brother Brian is at well-deserved 14k already xD! Love this vid

  • @valbonite5389
    @valbonite5389 3 ปีที่แล้ว +4

    Damn I was just looking for modal tutorials for my React portfolio. Brian clutch!!!

  • @ArcherJ1
    @ArcherJ1 3 ปีที่แล้ว +2

    Love the way you built this. It leaves room to create more than one modal and style it easily. The only thing I'm having trouble with is getting it to render with portal.

  • @sthefanocarvalho2823
    @sthefanocarvalho2823 2 ปีที่แล้ว

    Awesome. Solved my problem. Thanks again, Brian

  •  2 ปีที่แล้ว

    Thank you for the clean and the practical solution!

  • @ZEESHANJUNAID2222
    @ZEESHANJUNAID2222 3 ปีที่แล้ว +2

    Looks great. I have used react-modal with one of my nextJS project and the only thing i had to figure out was the animation on modal close. I think there's props named closeTimeoutMS which allow modal close delay and we can add animations when modal closes.
    Nice work though :)

    • @briandesign
      @briandesign  3 ปีที่แล้ว

      nice! yeah I wanted to make one from scratch, but react-modal pretty much does the same thing

  • @80Vikram
    @80Vikram 3 ปีที่แล้ว

    Thanks for your awesome efforts, kindly take care of background noise. God bless you man

  • @dearesthui
    @dearesthui 2 ปีที่แล้ว

    Thanks for this tutorial. Really helpful for what I need. Keep up the good work.

  • @jiwanjeon3319
    @jiwanjeon3319 2 ปีที่แล้ว

    This is a very good tutorial for beginners! I really appreciate your effort!!!

  • @damislav
    @damislav 3 ปีที่แล้ว

    Thank you. Very easy to understand

  • @aileen55
    @aileen55 3 ปีที่แล้ว +1

    You're so entertaining to watch hahaha

  • @charliebrewer1668
    @charliebrewer1668 2 ปีที่แล้ว

    Thanks again!!!

  • @rohitagni
    @rohitagni 3 ปีที่แล้ว

    This is just what I wanted. Cheers man !

  • @anuragk6722
    @anuragk6722 3 ปีที่แล้ว

    Amazing tutorial. absolutely loved it.

  • @denisvradiy8503
    @denisvradiy8503 3 ปีที่แล้ว +1

    nice video! please do more react videos)

    • @briandesign
      @briandesign  3 ปีที่แล้ว

      I got a new react website vid dropping tomorrow

  • @Krentiles
    @Krentiles 2 ปีที่แล้ว

    Thank you!

  • @MaltonCanada
    @MaltonCanada 2 ปีที่แล้ว

    Thanks brother

  • @lucasbertoldo5062
    @lucasbertoldo5062 3 ปีที่แล้ว

    Thank you very much, man! You saved me

  • @tinalee8686
    @tinalee8686 2 ปีที่แล้ว

    Thanks you! Helped a lot

  • @ansulp5799
    @ansulp5799 3 ปีที่แล้ว

    Thanks Brian, awesome work. Looking forward for more React videos 👍

  • @InverserPro
    @InverserPro 2 ปีที่แล้ว

    Thank U, bro!

  • @Merig93
    @Merig93 3 ปีที่แล้ว

    You could render the modal conditionally directly in App, by doing {showModal && }.
    This way you dont need to pass showModal as a prop and it's cleaner imo.

    • @briandesign
      @briandesign  3 ปีที่แล้ว +3

      that works too! you could also just add onClick={e => e.stopPropagation()} on the Modal div and remove the useRef completely and it still would work. I just wanted to show useRef for this example

  • @sarangkumar3803
    @sarangkumar3803 3 ปีที่แล้ว +1

    Can you explain, Why you used useCallback hook and its reference in useEffect hook as a dependency? Thanks in advance.

  • @infoberitabola7826
    @infoberitabola7826 3 ปีที่แล้ว

    Nice tutorial !!! Greeting from Indonesia

  • @edmundodominguezagurcia7254
    @edmundodominguezagurcia7254 3 ปีที่แล้ว

    Excellent video!

  • @longbka
    @longbka 3 ปีที่แล้ว +2

    Can you make these tutorials an dashboard admin with styled component

  • @Arundhativlog
    @Arundhativlog 2 ปีที่แล้ว

    I used this pop-up and I want to remove body scroll when pop-up is opened, can You please help?

  • @georgemoayi
    @georgemoayi 3 ปีที่แล้ว

    Ah yes we already kno Issa hit. Preciate da vid Brian I needed it

  • @pawels8040
    @pawels8040 3 ปีที่แล้ว

    Very nice , thanks mate !!

  • @JoaomdvFerreira
    @JoaomdvFerreira 3 ปีที่แล้ว

    Another smooth video man! Clean and simple just how we like it. A quick question regarding the styled components, as fine as they look like and the perks that comes within, they have a gigantic downside for me, browser console debugging. I've found a way to give them the classes that i want but it feels like an unnecessary use of code lines. Just wanted to know from your experience what's actually worth more in the long term: Styled Components or Normal Html?

    • @briandesign
      @briandesign  3 ปีที่แล้ว

      depends how simple your project is. You could try coding it up with regular html and css, then convert it into styled components after if it's hard to tell what is what

  • @tonymathew9469
    @tonymathew9469 3 ปีที่แล้ว +1

    Hi @Brian, great tutorial! Could you also tell us how we could make this responsive for smaller screens? It would really help, thanks!

    • @raphaeltorsu8655
      @raphaeltorsu8655 2 ปีที่แล้ว

      I think with a few media queries, it should be plausible

  • @surendrareddyseelam9757
    @surendrareddyseelam9757 3 ปีที่แล้ว

    You are awesome dude

  • @ebjrtux
    @ebjrtux 3 ปีที่แล้ว

    Congrats, great job!!!

  • @wijaksanapanji
    @wijaksanapanji 3 ปีที่แล้ว +1

    Love it❤️

  • @mohammedirfan-us6cf
    @mohammedirfan-us6cf 3 ปีที่แล้ว

    Big fan ...love from india

  • @litsoschastlivyy7002
    @litsoschastlivyy7002 3 ปีที่แล้ว

    hey man sweet video could you do one on how to link your modal to a table

  • @meredithjones7534
    @meredithjones7534 3 ปีที่แล้ว +1

    Thanks for the awesome tutorials! They have been a huge help building up my portfolio!
    I hit a blocker on this one though, no matter what I've tried I cannot install the react-spring package. I use npm and tried what you did in the video, tried installing globally, and tried installing --save with no luck.
    Any suggestions for a workaround?

  • @saivivekravi4979
    @saivivekravi4979 3 ปีที่แล้ว +3

    Can you make these toutorials with materialui as many are waiting for this

  • @markaguilar736
    @markaguilar736 3 ปีที่แล้ว

    very usefull

  • @jhonvaron1721
    @jhonvaron1721 2 ปีที่แล้ว

    Hello friend, how do you make the stylecomponent code look like this for you and not like it looks like a string for me?

  • @Dzirmal
    @Dzirmal 3 ปีที่แล้ว

    Thanks, Great Job.!!!

  • @alekseytrump1586
    @alekseytrump1586 3 ปีที่แล้ว

    Super Dev!))))

  • @chalermkhwannasritha7431
    @chalermkhwannasritha7431 3 ปีที่แล้ว

    yayyyy, thanks Brian!

  • @rahulvirat7859
    @rahulvirat7859 3 ปีที่แล้ว

    Nice bro

  • @therevenant9296
    @therevenant9296 2 ปีที่แล้ว

    I need to implement this in my Navbar. I tried and the modal seems to misalign from page.

  • @minhtriha1222
    @minhtriha1222 3 ปีที่แล้ว +1

    Thank Brian. Well done!
    But I still stuck at closing animation( the modal flow up then disappear). Can you help me and everybody here to solve this

    • @briandesign
      @briandesign  3 ปีที่แล้ว

      are there any errors in your console? or do you mean the animation doesn't work at all?

    • @minhtriha1222
      @minhtriha1222 3 ปีที่แล้ว

      @@briandesign Your code works well. I mean an additional animation when closing the Modal. In fact, the Modal immediately disappears when showModal: false. Would you consider adding a disappear animation for the Modal. I mean the Modal floats from middle to top of the page(opposite direction of showing Modal). I tried to add some css animation when showModal: false but the state immediately sets false and no animation happens, just disappear.

    • @colorfilter2046
      @colorfilter2046 3 ปีที่แล้ว

      @@minhtriha1222 I'm thinking about the same problem. Have you found a solution? If so, please share it with me.

  • @lennygonzalez2293
    @lennygonzalez2293 3 ปีที่แล้ว

    Awesome Videos!! I was wondering if you could include display content over react-icons (using styled components) in one of your tutorials??

    • @briandesign
      @briandesign  3 ปีที่แล้ว

      display content over react icons? I'm not sure what you mean

    • @lennygonzalez2293
      @lennygonzalez2293 3 ปีที่แล้ว

      @@briandesign Sorry for explaining it poorly... I meant when you hover over an icon and display text. Also thank you for responding thats awesome

  • @eddyed3212
    @eddyed3212 3 ปีที่แล้ว

    what if this modal should updated the environment that it is triggered from, then it will make the modal close, and it is not the behaviour that you may want

  • @hariace08
    @hariace08 3 ปีที่แล้ว

    How can we trigger the modal without a Button? For example every time a user logs in, a model appears after few sec on the landing page .

  • @synaxreader9326
    @synaxreader9326 2 ปีที่แล้ว

    On @21:13, I got an error in my console stating: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:....etc. I am buffled as to the reason why? Do you have any suggestions?

  • @rayvincentdelacruz8251
    @rayvincentdelacruz8251 3 ปีที่แล้ว

    Nice bruh!

  • @papichongogamer6144
    @papichongogamer6144 2 ปีที่แล้ว

    Great! Only you mist hover function 🤭

  • @yuricavalini3718
    @yuricavalini3718 3 ปีที่แล้ว

    Hello, Brian! First, thank you for this tutorial! I really enjoy your channel.
    I'm getting warning message in the console about memory leak: "Warning: Can't perform a React state update on an unmounted component..."
    I tried to solve this, but didn't figure out how to handle this yet. As I can see you tried to manage it by passing a return statement in the useEffect. Are you or anyone else having this issue?

    • @briandesign
      @briandesign  3 ปีที่แล้ว

      check my github code and see if you mistyped something

    • @yuricavalini3718
      @yuricavalini3718 3 ปีที่แล้ว

      @@briandesign I did. Seems like it's an issue because of react's version and react-spring. Still don't know why this is happening, but removing the element solved the issue. Thank you.

  • @ememobongumoren
    @ememobongumoren 3 ปีที่แล้ว

    I know it's been three months since you uploaded the video, very nice tbh!!. But what how do i go about a displaying a modal popup on site load using react

  • @jonathanm.5813
    @jonathanm.5813 3 ปีที่แล้ว

    Thanks, I tried with NextJS ton include modal animation but useSpring and animated doesn't work for me. Any tip to adapt it ?

  • @goresometimes3528
    @goresometimes3528 3 ปีที่แล้ว

    Not sure if anyone will see this but I did this tutorial and the image wasn't rendering and I'm not sure what I missed. I followed it to a T and couldn't figure out why the image was broken. Would appreciate any help. Thank you.

  • @EzeJ99
    @EzeJ99 3 ปีที่แล้ว

    I love you so much man (no homo), thanks to you i can finish my personal website. Greetings from Argentina!

  • @rangabharath4253
    @rangabharath4253 3 ปีที่แล้ว

    awesome :)

  • @RemsterHD
    @RemsterHD 3 ปีที่แล้ว

    Awesome tutorial! Would you consider doing something similar but when you click on the modal you are able to switch between photos?

    • @briandesign
      @briandesign  3 ปีที่แล้ว +1

      like a photo gallery?

    • @RemsterHD
      @RemsterHD 3 ปีที่แล้ว

      @@briandesign Yeah I was thinking where you have a project modal, once hovered, it will show the "learn more" then you click on it then the modal will open and then within that modal it would have some details about the photo you are looking at. Also give the user the ability to click through the photos and then depending on the photo the user is viewing the text/details of the photo change as well. This is defiantly more advanced but would be awesome to see!

  • @aistetamosauskiene1234
    @aistetamosauskiene1234 3 ปีที่แล้ว

    Thank you for the video. Have a question: Modal component has showModal and setShowModal props, what are the types of those props?

    • @jabulaniemmanuelshili505
      @jabulaniemmanuelshili505 3 ปีที่แล้ว

      my guess would be one is a boolean and one is a function , as in showModal is a boolean and setShowModal is a function.

  • @dhimasdhias22
    @dhimasdhias22 3 ปีที่แล้ว

    another cool tutorial, thanks, Brian!
    anyway, would you consider doing a Contact Form using React and Firebase? :D

    • @briandesign
      @briandesign  3 ปีที่แล้ว

      Possibly!

    • @dhimasdhias22
      @dhimasdhias22 3 ปีที่แล้ว

      @@briandesign cant wait for it 🤣

  • @PwnUrBadCock
    @PwnUrBadCock 3 ปีที่แล้ว

    Big thanks for this video man.
    However, I faced one issue while working on my project. Inside of return function I have a map method, which takes a lot of pokemon cards, each card has a learn more button. The idea was to create a Modal which will be individual for each pokemon card. However, when I click learn more button, Modal opens up and always showing the very last pokemon information. Probably because initial render occurs instantly after the npm start, and all modals are taking the very last item from the map.
    Can you please make a tutorial on how to use Modal inside of the map? Maybe internet shop with different items where each item has it's own Modal. That would be awesome!
    Cheers!

    • @briandesign
      @briandesign  3 ปีที่แล้ว

      yeah I can make one in the future. It sounds like an image gallery design would replicate what you're trying to do. Basically you click on an image and it only shows that specific one. I made something similar with regular javascript, but I'd have to refactor it in react

    • @PwnUrBadCock
      @PwnUrBadCock 3 ปีที่แล้ว

      @@briandesign That's a big hint! I will try to Google image galleries powered by react.

  • @swevos7632
    @swevos7632 2 ปีที่แล้ว

    Hello, what do you use as extension to have this kind of colors ?

  • @sivaganesh4489
    @sivaganesh4489 3 ปีที่แล้ว

    pls do more videos on react design

  • @dixondeuxyeux
    @dixondeuxyeux 3 ปีที่แล้ว

    Hello Brian, get tutorial. I have used modals in html projects. This looks far more difficult to code and I also wanted to ask how does one use multiple modals with different images and text on a page?? Many thanks

  • @80Vikram
    @80Vikram 3 ปีที่แล้ว

    Nothing is UP in morning time, only after 21:00

  • @makak360
    @makak360 3 ปีที่แล้ว

    Hy dudes , for me img don't display with relative or absolute path , anyone have an idea ?

  • @shubhammetkar6021
    @shubhammetkar6021 3 ปีที่แล้ว +1

    Is it responsive?

  • @shayanjafari1935
    @shayanjafari1935 3 ปีที่แล้ว

    hello when i use the styled component they show green and the snippet is off what should i do??????

    • @briandesign
      @briandesign  3 ปีที่แล้ว

      add the extension vscode-styled-components

  • @soniakashyap6261
    @soniakashyap6261 3 ปีที่แล้ว

    My Img is not showing can u tell me where is the prob

    • @damislav
      @damislav 3 ปีที่แล้ว

      add .default after brackets

  • @mbilal02
    @mbilal02 3 ปีที่แล้ว

    Hello Respected Sir, Please make a water ripple effect on the background banner/header/hero image video in react js please sir

  • @Nathan-pu9um
    @Nathan-pu9um 3 ปีที่แล้ว

    just wandering how to stop scrolling if say you clicked the modal half way down the page in another section

    • @sreekar_s
      @sreekar_s 3 ปีที่แล้ว

      On launching the modal, execute this:
      document.body.style.overflow="hidden"
      On close, execute this:
      document.body.style.overflow="visible"
      Hope this is what you are looking for

    • @arundhati7163
      @arundhati7163 2 ปีที่แล้ว +1

      @@sreekar_s Can you pls share the short video On launching the modal, execute this:
      document.body.style.overflow="hidden"
      On close, execute this:
      document.body.style.overflow="visible"

  • @vijuvaghish2592
    @vijuvaghish2592 3 ปีที่แล้ว

    why you use require for img in modal.

    • @briandesign
      @briandesign  3 ปีที่แล้ว

      react has issues with regular imports, so I use require to get the image. If that doesn't work, you can always go to the top of file and import {Image} from './modal.jpg' then pass 'Image' for the src like and that should work as well.
      If you just search on stackoverflow you should see a bunch of examples using the import {Image} from 'imagelink'. There's a few alternatives as well, but this should work. If not let me know

  • @LarsRyeJeppesen
    @LarsRyeJeppesen 2 ปีที่แล้ว

    This is not lazy loaded.

  • @JounitoJons
    @JounitoJons 3 ปีที่แล้ว

    Portals?

    • @briandesign
      @briandesign  3 ปีที่แล้ว +1

      yeah you could use portals too, but I wanted to keep this template simple so people can refactor and add extra things

  • @dhanushr6172
    @dhanushr6172 3 ปีที่แล้ว

    Is that modal responsive?

    • @briandesign
      @briandesign  3 ปีที่แล้ว

      this just shows the open/close functionality

    • @dhanushr6172
      @dhanushr6172 3 ปีที่แล้ว

      @@briandesign thank you

  • @alexgreen3630
    @alexgreen3630 3 ปีที่แล้ว

    Thanks bro