Modal in ReactJS - Code a React Modal Tutorial using Hooks

Поділитися
Вставка
  • Опубліковано 17 лис 2024

КОМЕНТАРІ • 174

  • @rBroneak
    @rBroneak 3 роки тому +1

    Thanks for the tutorial. Tip to share back. When you break up you’re content you can use semantic html tags and add few identifiers and layout helpers. No need for all the extra divs and class names until it gets “special”.
    modal..container > header + section+footer
    Now you can target all your general modal bits via the parent .modal class.
    .modal header {}
    Or scss
    .modal {
    header{}
    section{}
    footer{}
    &.modal-special {
    // now when this class is added to your modal you extend the base styles and add more control
    header {
    Something: special;
    }
    }
    }
    Etc. been working for me for a long time to build and extend components and decorators. I use a prefix on the top level class with cp_ or something to denote its a component (used more than once and has a specific style sheet)

  • @pannihto7588
    @pannihto7588 3 роки тому +39

    () => closeModal(false) is a terribly confusing way to close the modal(since the parameter value implies that you're not closing it) . Should have passed closeModal={()=> setModal(false)} and then just call closeModal without any parameters

    • @synthrunner4244
      @synthrunner4244 2 роки тому +5

      Better yet, create a handleModal function, and change the state of the modal to = setModal(!isOpen). that way its a function that will alway do the opossite of the value inside the modal open state

    • @spritemoney
      @spritemoney Рік тому

      Where is this at in the video?

  • @KJMacoustic
    @KJMacoustic 3 роки тому +1

    stumped on how to make a modal in react for days because of state and hooks but you made it so easy to understand in this video! Thanks!

  • @levyroth
    @levyroth 3 роки тому +17

    Dude, make a Patreon or something. Great video as always, so clear and straightforward. You should be teaching CS classes for 1st year students or high school students.

    • @PedroTechnologies
      @PedroTechnologies  3 роки тому +9

      Thank you Levy! Some people asked me about a patreon or something like that but I didn't want to make it without giving any other value out of it. But recently I've been setting up the youtube's membership program and I might turn it active soon. Members will be able to access videos before I post and also have badges next to their names. I also recorded like 80 videos explaining coding interview questions when I was studying but I never posted them hahaha so maybe I will post them for members. I am still a junior in college but I wish I could be a professor lmaoo

  • @jjrise
    @jjrise 2 роки тому +1

    well this was a welcome surprise... I can't tell you why, but this was probably the 15th video I've watched on Hooks and it clicked for me. Your teaching style is fantastic. Keep it up!

  • @ckh8217
    @ckh8217 3 роки тому +19

    Nice channel Pedro! Just a small tip for the close button, I think the HTML-entity "×" looks better than the letter X

    • @pupil_1
      @pupil_1 Рік тому

      Better to use font awesome

  • @Kuena866
    @Kuena866 2 роки тому

    PedroTech has been added to my favourite coding channels........... Good work

  • @oussamakrab6378
    @oussamakrab6378 3 роки тому +10

    Pedro u saved my ass with ur tutorials for my final project thanks buddy

  • @jaia466
    @jaia466 3 роки тому +1

    The best channel for me to learn React! The contents are more likely a real world implementation when creating a project especially for a beginner like me. Thanks Pedro! :)

  • @wawayltd
    @wawayltd 11 місяців тому

    Straight to the point in easy and short manner. Thanks!!

  • @SudaMasakii
    @SudaMasakii 2 роки тому +1

    まじで分かりやすい!
    詰まってましたけど先に進むことができました!

  • @amanpreetsingh7449
    @amanpreetsingh7449 2 роки тому

    Thank you so much for this tutorial. I was stuck for some time on how to approach this issue of modal in my project. Short and concised explanation. 👍👍👍👍 Thank you

  • @chandrakant6283
    @chandrakant6283 2 роки тому +1

    Brilliantly explained, thanks man.
    I just needed the right logic to make it work.

  • @AnshumanBisoyi
    @AnshumanBisoyi Рік тому +1

    Dude you teach so good, want more vids more on animations from you.

  • @saidmaroc8448
    @saidmaroc8448 3 роки тому +1

    I was looking at WinBox React when you published this post. Top as usual

  • @dbiswas
    @dbiswas Рік тому +2

    This is simply awesome, exactly what I was looking for. But can you also include on how to pass the return value when Cancel v/s continue is selected? Because based on that input you may want to drive other functionality.

  • @khizrshaikh9902
    @khizrshaikh9902 2 роки тому +1

    Finally Done After 2-3 days
    Thanks for this buddy

  • @joenacouzi558
    @joenacouzi558 3 роки тому

    in working in a job that requires reactjs and everything i wanna do you have the right tutorial for it . thank you !

  • @AarviJain-v8m
    @AarviJain-v8m 7 місяців тому

    Thank you so much for making this video seriously very easy way to create custom model .
    I watch lots of video but this one is superb🤩🤩🤩🤩🤩

  • @dawoodshahzad9082
    @dawoodshahzad9082 3 роки тому +4

    And now another master piece. Thanks buddy!

  • @Usernamesareoutdated
    @Usernamesareoutdated 2 роки тому +3

    Many people are calling the Modal from the middle or side of the html document - not from the top. For those who are using the Modal within a nested div and its not centered on the screen, add left:0; right:0; to modalBackground class and change position:relative to position:absolute, and it will take up the expected screen portion.

  • @austintochukwuasoluka1502
    @austintochukwuasoluka1502 2 роки тому +2

    Thank you so much.
    What's the difference between this approach and using portals?

  • @orkoren2006
    @orkoren2006 2 роки тому

    Short and concise Pedro. Thanks!

  • @owltrades
    @owltrades 3 роки тому +3

    Thanks Pedro for this video, can you please teach us how we can use little bit of animations like smooth scrolling on clicking menu, image unbluring on scrolling to specific section in our web page cause every tutorial sucks they make everything super complicated....

    • @PedroTechnologies
      @PedroTechnologies  3 роки тому +2

      Yeah sure! I am thinking of doing some other UI stuff!

  • @AjaxAson
    @AjaxAson Рік тому

    Wow....That's Fkn awesome Pedro. Really worked 😍😍

  • @parasjangid5721
    @parasjangid5721 2 роки тому

    This is what i say perfect way to explain.....love from india 😍

  • @gustavokazuo1834
    @gustavokazuo1834 2 роки тому

    Thank you, I'm brazilian, your video helped me. ;)

  • @PanlasangMotour
    @PanlasangMotour 3 роки тому +2

    Awesome !! Kindly implement some crud operation with db with this modal

    • @PedroTechnologies
      @PedroTechnologies  3 роки тому +2

      Hmm I am honestly thinking about making a video incorporating both cool UI stuff and cool backend stuff. I could defo include a modal :)

  • @MrAndykofi
    @MrAndykofi 2 роки тому +1

    Nice work, subscribed. I like your eloquency.

  • @francescoanastasio2021
    @francescoanastasio2021 4 місяці тому

    Thank you for the video, I have a question: why we opt for position: fixed; here? Wouldn’t absolute make more sense?

  • @owltrades
    @owltrades 3 роки тому +3

    Pedro this modal should close on clicking background or clicking outside of the actual modal.

    • @PedroTechnologies
      @PedroTechnologies  3 роки тому +3

      Damn that would've been a cool thing to implement as well, to do that you can just make the background div be clickable and if you click on it you setOpenModal(false)

    • @levyroth
      @levyroth 3 роки тому

      I actually prefer it doesn't because you could put a form in a modal and you don't want it to go away if you misclick something. Depends on what you want to do with the modal really.

    • @ViewFromAndromeda
      @ViewFromAndromeda 3 роки тому

      @@PedroTechnologies But won't that make everything also close on click since that div wraps everything within?

  • @MilanDrazic
    @MilanDrazic 3 роки тому +2

    you did not show how the content disappeared
    open modal button when you clicked?

  • @jasonhuang4333
    @jasonhuang4333 2 роки тому +6

    Very helpful. Just one question, should we use react.createPortal and render it outside of root div or just use css and html to create a basic modal

    • @ashishprasad2163
      @ashishprasad2163 2 роки тому

      Using reactDOM.createPortal is the best approach, highly scalable and no dependencies on third party packages.

  • @joenacouzi558
    @joenacouzi558 3 роки тому

    You bro are my Reactjs Savior !!!

  • @ahmedabdelmoneam9279
    @ahmedabdelmoneam9279 Рік тому

    Very useful, simple and obvious. Thanks

  • @GilAguilar
    @GilAguilar 2 роки тому

    Thanks for the great video, it was very straight forward and simple to follow.

  • @igorgoncalves5691
    @igorgoncalves5691 Рік тому

    Nice tutorial Pedro, thanks so much.

  • @umadhityamathi6804
    @umadhityamathi6804 2 роки тому

    Very much helpful, In right time.
    Thank you

  • @quirinopls
    @quirinopls 3 роки тому +1

    Vlw pedrão, vc é muito brabo cara

  • @paragbabiya1798
    @paragbabiya1798 Рік тому

    bro you save my job thank you

  • @M4nudu45
    @M4nudu45 3 роки тому

    it helped me a lot and I really understood, thanks bro :D

  • @notcountdankula
    @notcountdankula 2 роки тому

    Thank You. Very Helpful Video

  • @robertramirez8142
    @robertramirez8142 2 роки тому

    This a tutorial was very helpful thanks.

  • @wpxpert98
    @wpxpert98 2 роки тому

    I really like your videos, keep it up

  • @dwaipayanmunshi7691
    @dwaipayanmunshi7691 3 роки тому +1

    Hey, Could you make a tutorial on how to Handle Multiple Modals in a Single Component using useState ?

  • @clairesingson3331
    @clairesingson3331 Рік тому

    hi . .good tut . ..
    just wanna ask if we can make the background transparent so that we would still be seeing our page in the background? do you have a tut regarding that? transparent with modal? thank you ..

  • @kerwincharles7832
    @kerwincharles7832 2 роки тому +1

    At 13:22 you show the modal appearing below the h1 tag from the App component. Then you stop the video and return with CSS that makes the that h1 tag disappear. How? Setting position to fixed for className modalBackground doesn't result in that behavior for me. Did something change in any of the components?

    • @kerwincharles7832
      @kerwincharles7832 2 роки тому

      Will need to include top: 0 and left: 0 to achieve this look

  • @电波鼠
    @电波鼠 2 роки тому

    this is helpful for me,thank you!!

  • @saurabhranjan4951
    @saurabhranjan4951 2 роки тому

    Hey could you explain how to use Modals on already existing button?

  • @Akash-xv5sk
    @Akash-xv5sk Рік тому

    How to send an image to backend in an existing form like i have multiple input fields, in that i want to append an image, what are the proper way to send an image to backend. like base64 or JSON.stringify or ..???. I appreciate your effort and thankyou

  • @itsmayur4845
    @itsmayur4845 2 роки тому

    hey, I tried this ...my scenario is I am using a button in the form in which Model/popup should be called without rendering the existing form component, but I am unable to do so. Please help!!

  • @thamismedina6394
    @thamismedina6394 2 роки тому

    I have question, what if a need multiple modals in multiple buttons? how can i do it? is the only way using context?

  • @gromfader6559
    @gromfader6559 2 роки тому

    This was great! Thank you!

  • @zainabideen8144
    @zainabideen8144 Рік тому

    What if I want a popup above the content with the backdrop effect?

  • @idanbarzilay5289
    @idanbarzilay5289 2 роки тому

    can you make a video on creating a modal with forwardRef useImperativeHandle?

  • @anthonyanselmo9889
    @anthonyanselmo9889 3 роки тому

    Awesome Video! I was wondering if there is a way to create multiple modals when one closes another opens. For example, I'm creating a site for email templates I use for work. I am trying to get the Modal to open up a form where I insert some information like an email address and a Customers name. I press an enter button in that modal and it will close the form and open the email so I can copy the text. Sorry if this doesn't make sense.

  • @konstantinsnihyr3408
    @konstantinsnihyr3408 Рік тому

    what if multiple pages not only App.js so I have to use useState on every page to open/close modal? do you think this is good solution?

  • @hardwired66
    @hardwired66 3 роки тому +1

    thanks you pedro 👍👍

  • @bubumunhuu4112
    @bubumunhuu4112 2 роки тому

    Worked thank you a lot.

  • @gamerpotato2463
    @gamerpotato2463 3 роки тому

    Wait, the content in the main page is gone when you open the modal.

  • @dragosp.7635
    @dragosp.7635 2 роки тому

    Can you make a video for cookie policy? (displayed like a modal)

  • @muhammadjonnazarov146
    @muhammadjonnazarov146 2 роки тому

    Great Tutorial, Thanks alot

  • @taker610
    @taker610 2 місяці тому

    I had to add top: 0, left: 0 after position: fixed or else my modal would not appear at all. If you're putting your model on top of other content you will need the top and left defined to make this layout work.

  • @sonwander1
    @sonwander1 2 роки тому

    Hello, how to set the modal to open on page load?

  • @haian_
    @haian_ 2 роки тому

    How to close when click outside modal?

  • @arinzechukwuhillary0zor644
    @arinzechukwuhillary0zor644 2 роки тому

    Thanks, man for this is helpful

  • @JadeclonOfficial
    @JadeclonOfficial 3 роки тому

    Hmm, when I download your code and open the modal, the text and open button dont disappear

  • @kumardipsaha8964
    @kumardipsaha8964 2 роки тому

    Thank you so much for this video...🤗🤗🤗

  • @wiaanduvenhage3082
    @wiaanduvenhage3082 2 роки тому

    Thanks for the video! But just a quick question, how would I go about importing that same modal component but just it having extra inputs. Is there a way of doing that? Sorry if the question is unclear

    • @raoasim4927
      @raoasim4927 2 роки тому

      you can use condition rendering inside the model component and change the conditions on your clicks

  • @walterhumphreys671
    @walterhumphreys671 2 роки тому

    const [display, setDisplay] = React.useState(false); the modal is not listening and it always keeps open, if i use const [display, setDisplay] = React.useState(initialState:false);, i the error The type cast expression is expected to be wrapped with parenthesis,, and if do, const [display, setDisplay] = React.useState({initialState:false}); it still does nothing the modal is always open and close button don't work either

  • @habibalnoman845
    @habibalnoman845 Рік тому

    Nice explanation

  • @joenacouzi558
    @joenacouzi558 3 роки тому

    I got a question if i wanna do a modal box where i say this good or this is bad do i create 2 modal.js ? or 2 function or can i do 2 functionalities in 1 ?

  • @uwuslayer0211
    @uwuslayer0211 2 роки тому

    getting Uncaught (in promise) Error: Cannot find module when i try to import the css file even though the css file is in the same directory as the App.js. im trying to import the css by import './form_style.css'

  • @henrykibocha5224
    @henrykibocha5224 3 роки тому

    Thanks for this awesome tut mehn!
    Can this be a link on the navigation menu eg (signup / login / free trial ) how would that be implemented?

  • @SanjayKumar-un7xf
    @SanjayKumar-un7xf 2 роки тому

    Thanks for sharing knowledge :)

  • @danielsantiagocuellarmuril2034
    @danielsantiagocuellarmuril2034 3 роки тому +1

    muy buen video, gracias amigo!!

  • @mmaanii
    @mmaanii 2 роки тому

    How to perform Crud operations inside the Modal...!

  • @Leo-es3fq
    @Leo-es3fq 3 роки тому

    How can i open new modal from other modal?

  • @philcobjosol
    @philcobjosol 8 місяців тому

    Why do you always write space after opening tags?

  • @Menix-genziara
    @Menix-genziara 3 роки тому

    What color theme are u use?

  • @ThColinPereira
    @ThColinPereira 3 роки тому

    this is so cool, thanks bud

  • @naumanshigri
    @naumanshigri 3 роки тому

    xharingmo xng ly mili ata . du liye na liyahmo yod xug .. very help full

  • @vidal7368
    @vidal7368 3 роки тому +1

    opa eae, daria para fazer usando context tbm né?

    • @PedroTechnologies
      @PedroTechnologies  3 роки тому

      Sim! Da pra fazer muita coisas com modal, essa versão acabou ficando bem simples!

  • @LoneWolfCodingProfessional
    @LoneWolfCodingProfessional Рік тому

    what about modal on top of modal?

  • @alvinrisqianto5380
    @alvinrisqianto5380 3 роки тому +1

    Pedro, you need to set some admin in your discord community because you're rarely active on discord when there's a problem in your community group. Yesterday there's a spammer on the group, so I hope there's another admin who can ban this person. Or at least, you can check your group very often if you want.

    • @PedroTechnologies
      @PedroTechnologies  3 роки тому

      Hey, thank you for letting me know. I saw this a few minutes before you commented and spent some time thinking on what to do. I decided to delete the server. I couldn't manage the server and couldn't be active there because of work/school. So the server would be vulnerable to scammers/bad people. I wouldn't want any of my subs to be scammed so I decided that as long as I can't personally moderate the server, it's better to not have it. Hope you understand!

  • @andrealeon8415
    @andrealeon8415 2 роки тому

    Gracias me ayudaste mucho

  • @TheCataguases
    @TheCataguases 3 роки тому

    Como eu faria para avançar de um modal para o outro?

  • @jasurhaydarovcode
    @jasurhaydarovcode 3 місяці тому +1

    thanks for video i like

  • @worldclasscode1847
    @worldclasscode1847 2 роки тому

    Great video! :)

  • @kwameaddo1007
    @kwameaddo1007 2 роки тому

    great video bro,

  • @aliciaweenum1248
    @aliciaweenum1248 3 роки тому

    Great video, thank you

  • @shashankdewangan455
    @shashankdewangan455 3 роки тому

    please tell me does it work on react-native?

  • @triptichhetri
    @triptichhetri 2 роки тому

    Many Many thanks 🙌

  • @sophiziia
    @sophiziia 9 місяців тому

    Thank you so much!!

  • @abderrahmaneradiohead9791
    @abderrahmaneradiohead9791 2 роки тому

    can i add video in this modal ?

  • @summayanadaf7537
    @summayanadaf7537 2 роки тому

    You have to show the css which you not created in video..

  • @DhanByCode
    @DhanByCode 3 роки тому

    Pedro please create tutorial react hooks with firebase for beginnner

  • @ТёмаКоролёв-к6ф
    @ТёмаКоролёв-к6ф 3 роки тому +1

    Но что если на странице должно быть несколько модальных окон с разным контентом?

    • @PedroTechnologies
      @PedroTechnologies  3 роки тому

      I don't know what that means hahaha but my answer is yes

    • @PedroTechnologies
      @PedroTechnologies  3 роки тому

      Just translated it hahaha, if you want multiple modals then you can pass the title, the description and the button through props.

  • @growthhacking9126
    @growthhacking9126 3 роки тому +1

    Thanks man

  • @Pareshbpatel
    @Pareshbpatel 2 роки тому

    Excellent video on creating a Modal Component. Thanks, Pedro
    {2022-02-22}