Modal in ReactJS - Code a React Modal Tutorial using Hooks

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

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

  • @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?

  • @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!

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

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

  • @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

  • @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!

  • @wawayltd
    @wawayltd ปีที่แล้ว

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

  • @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

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

    Finally Done After 2-3 days
    Thanks for this buddy

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

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

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

    And now another master piece. Thanks buddy!

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

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

  • @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! :)

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

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

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

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

  • @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?

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

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

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

    Short and concise Pedro. Thanks!

  • @AjaxAson
    @AjaxAson ปีที่แล้ว

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

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

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

  • @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.

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

      style={{Margin: "auto"}}

  • @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.

  • @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

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

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

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

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

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

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

  • @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🤩🤩🤩🤩🤩

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

    You bro are my Reactjs Savior !!!

  • @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.

  • @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?

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

    Nice work, subscribed. I like your eloquency.

  • @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?

  • @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?

  • @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

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

    Very useful, simple and obvious. 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!

  • @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 ..

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

    Vlw pedrão, vc é muito brabo cara

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

    bro you save my job thank you

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

    Very much helpful, In right time.
    Thank you

  • @igorgoncalves5691
    @igorgoncalves5691 ปีที่แล้ว

    Nice tutorial Pedro, thanks so much.

  • @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

  • @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 ?

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

    I really like your videos, keep it up

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

    Thank You. Very Helpful Video

  • @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 :)

  • @yashkhatwani230
    @yashkhatwani230 8 วันที่ผ่านมา +1

    Thanks a lot enjoyed it

  • @电波鼠
    @电波鼠 2 ปีที่แล้ว

    this is helpful for me,thank you!!

  • @zainabideen8144
    @zainabideen8144 ปีที่แล้ว

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

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

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

  • @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'

  • @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

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

    This a tutorial was very helpful thanks.

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

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

  • @Menix-genziara
    @Menix-genziara 3 ปีที่แล้ว

    What color theme are u use?

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

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

  • @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

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

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

  • @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.

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

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

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

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

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

    This was great! Thank you!

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

    How to close when click outside modal?

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

    Worked thank you a lot.

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

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

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

    Nice explanation

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

    Thanks, man for this is helpful

  • @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.

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

    Great Tutorial, Thanks alot

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

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

  • @dragosp.7635
    @dragosp.7635 2 ปีที่แล้ว

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

  • @SanjayKumar-un7xf
    @SanjayKumar-un7xf 3 ปีที่แล้ว

    Thanks for sharing knowledge :)

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

    thanks you pedro 👍👍

  • @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!

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

    muy buen video, gracias amigo!!

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

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

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

    please tell me does it work on react-native?

  • @Leo-es3fq
    @Leo-es3fq 3 ปีที่แล้ว

    How can i open new modal from other modal?

  • @philcobjosol
    @philcobjosol 9 หลายเดือนก่อน

    Why do you always write space after opening tags?

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

    Gracias me ayudaste mucho

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

    can i add video in this modal ?

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

    this is so cool, thanks bud

  • @LoneWolfCodingProfessional
    @LoneWolfCodingProfessional ปีที่แล้ว

    what about modal on top of modal?

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

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

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

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

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

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

  • @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?

  • @ТёмаКоролёв-к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.

  • @sophiziia
    @sophiziia 10 หลายเดือนก่อน

    Thank you so much!!

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

    great video bro,

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

    Great video, thank you

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

    Many Many thanks 🙌

  • @jasurhaydarovcode
    @jasurhaydarovcode 4 หลายเดือนก่อน +1

    thanks for video i like

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

    Thanks man

  • @EkUntoldKahaani
    @EkUntoldKahaani ปีที่แล้ว

    Thanks mate ❤

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

    can we use this for crud edit?

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

      should probably have shown a functionality Implemented on continue

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

      You can definitely do this! Whenever I implement an app where I can update a user info, I always pop a modal to confirm if they want to proceed with the changes!

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

      @@PedroTechnologies ur current crud tutorial doesn’t though? So the edit function should be called in the modal.js or app.js?

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

      @@MrFyce the crud video was mainly for beginners so i didnt want to overcomplicate it by adding a modal. But if you want to make it happen with a modal, you can add the axios api call inside of the modal! Or you can create a function that calls the update api request and pass it as props to the modal

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

      @@PedroTechnologies oh so basically the edit function is not called on click on the update button but on the ok button of the modal but I have to pass it as props?

  • @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!

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

    Pedro please create tutorial react hooks with firebase for beginnner