Drag and drop in react was a lot easier than I thought

Поделиться
HTML-код
  • Опубликовано: 18 окт 2024

Комментарии • 110

  • @dhunsworth
    @dhunsworth Год назад +33

    I always had in my mind that this would be super complex and definitely a situation to go looking for some package that would make it reasonable. Thanks for showing us this!

  • @buraksurumcuoglu8303
    @buraksurumcuoglu8303 Год назад +15

    I just got out of a meeting on my dev job and we talked about a new page with drag and drop functionality, your timing is incredible 😅

  • @51Grimz
    @51Grimz Год назад +4

    Useful video on a quick and simple native drag and drop without any libraries or anything! Follow up to this would be dragging and dropping in any index of the droppable area. Say you drag Widget C in between Widget A and B. Not just appending it to the end.

    • @estoupensa27
      @estoupensa27 Год назад +1

      Do you know how to drag and drop inside of the droppable area?

  • @saman6199
    @saman6199 Год назад +14

    This is awesome, I always avoided to even try this feature, because I thought it could be complicated. But you made it look so easy with your walkthrough. Will definitely give it a shot. Thanks for your effort 😊

  • @selahadinjemal7138
    @selahadinjemal7138 6 месяцев назад +1

    I just saw this in a job posting as a best to have skill and wanted to check it out. simple, effective, no blabber. Thanks!

  • @Gabrielmo00
    @Gabrielmo00 6 месяцев назад

    Best tutotial! I have had trouble with react drag and drop libraries in the past. I was in need to start a new project that woul require a simple drag and drop, and your example give me the kickstart that I need. Thanks man!

  • @Rico-cp4xp
    @Rico-cp4xp 6 месяцев назад

    Been looking into dnd lately, crazy how simple that is. Great video as always 👍

  • @eveguelarocha9961
    @eveguelarocha9961 Год назад +1

    I think just last week, I needed this kind of code in react, I ended up searching for code then copied and pasted it and just changed variables and stuff and it worked, but this video made me realize I need to recode it and do it with my own logic to improve my skills, Thanks mate! I thought it was so complicated, was thinking to use, dom manipulation etc but i think, i think too much on the problem. Thank you again, will keep following your page for more advice !

  • @siva002
    @siva002 Год назад

    So much easier to understand. Thank you. You saved me the trouble of going with react-dnd or dnd-kit which are very sophisticated, but overkill. As long as we don't need mobile or too much cross browser compatibility ( for example, internal websites), this is more than enough.

  • @ilovelctr
    @ilovelctr Год назад

    Wow, thanks a ton for this splendid tutorial! I didn't think this could be implemented using such exquisitely clean code, and thought that it might end up as equally annoying as if otherwise built via vanilla JavaScript and real DOM manipulation. Absolutely appreciate how elegant this is.

  • @ThisIsLiving__
    @ThisIsLiving__ Год назад +1

    I have always had a project in mind requiring me to use this feature - but eventually, the complexity of my ambition made me never do it but I ll definitely do it now

  • @saladin_advanced
    @saladin_advanced 2 месяца назад

    Best video explaining drag n drop.

  • @ZACKDEV
    @ZACKDEV Год назад

    Wow you made learning this super easy, I was looking into this feature recently with a lot of complicated topics. This make is super simple for us to recreate it and experiment!

  • @Earth_Elegance_
    @Earth_Elegance_ 4 месяца назад

    Thank you. This is easy than I thought. I realized it because of you

  • @matze489
    @matze489 Год назад

    this is amazing, i thought i would need to use some lib todo that but with knowing these events its actually pretty easy todo it on you own

  • @FXTripazha
    @FXTripazha Год назад

    Easier than I expected, thanks! Subscribed

  • @rredington305
    @rredington305 6 месяцев назад

    I've got this part sorted 👍🏼 next im working on a DnD sortable list using standard React without success. Pls make a DnD sortable list video 🙏🏻

  • @blu5037
    @blu5037 Год назад

    Nice video! Never implemented this feature, but for a long time I thought we'd have to track the cursor position and everything. Cool to see that it can be implemented with little lines of code.

  • @nonstopper
    @nonstopper Год назад +23

    Now make it re orderable

    • @zzzyyyxxx
      @zzzyyyxxx Год назад +2

      DND Kit makes this super easy to do

    • @harithmu
      @harithmu 8 месяцев назад +1

      you have a repo? because i find it very hard to do it where its something like in vid. (drag n drop but original item still there)

    • @ivan.jeremic
      @ivan.jeremic Месяц назад

      dndKit is amazing but the performance pf solidjs would be nice, if there where a similar lib in solidjs K would switch to solid

  • @Vimal-tr3tl
    @Vimal-tr3tl 5 месяцев назад

    Minimal much needed. Thank you.

  • @MahmoudBA
    @MahmoudBA Год назад

    you made it look so easy great work!

  • @ReDestro69
    @ReDestro69 Год назад

    Enjoyed this video. Apparently, I'm working on a client project where I'm building a module very similar to DocuSign. I'll be dragging different fields onto the document and assigning users to each field to fill out/sign.

  • @glcorreia
    @glcorreia 2 месяца назад

    I thought this would require plugins and a lot more code. Thanks for sharing

  • @noahwinslow3252
    @noahwinslow3252 Год назад

    I've been interested in making a game like stacklands for a while, perfect fun project with drag and drop

  • @estheryang6450
    @estheryang6450 10 месяцев назад

    Thank you for the explanation! Will love to ask what is the name of the extension you use to show component?

  • @TheBswan
    @TheBswan Год назад +1

    Dnd-kit is the best library for this

    • @ZACKDEV
      @ZACKDEV Год назад

      LOL WHAT THE HECK! it literally is the best!

  • @haze4828
    @haze4828 Год назад +1

    Would be pretty cool to make it remove the item from the original container once the drop has occurred, although I don't know how long that would take me to figure out 😅

  • @ryanwoods3333
    @ryanwoods3333 Год назад +1

    great video! would you consider doing a video in React where a user can click on a product for example and show a pop up modal? So there would be multiple modals with different content. Not sure how to do this in pure React without installing some NPM package...

    • @WebDevCody
      @WebDevCody  Год назад +2

      thank you for the super thanks! I could potentially do that for a react challenge video when I get time

  • @andlukas
    @andlukas 3 месяца назад +1

    i want to reproduce the behavior of google calendar, when you drag the amount of hours of an event

  • @serenity-sounds551
    @serenity-sounds551 21 день назад

    This was a helpful video for me.

  • @ifeanachofavour409
    @ifeanachofavour409 Год назад

    Hi that is really cool and I do currently have need for a drag and drop implementation.
    Wanted to ask if you could attach a link to the documentation for this.
    Hoping to hear from you soon. Thanks

  • @TheSourLemonz
    @TheSourLemonz Год назад

    Very informative, nice work

  • @xeliqa3921
    @xeliqa3921 Год назад

    how convenient. Am actually looking to build a project with this functionality, similar to a trello board.

  • @maxclouatre2703
    @maxclouatre2703 Год назад

    Love this! Custom starter or did you find this in the Vite docs? Thanks!

  • @MubashirullahD
    @MubashirullahD Год назад

    That was so cool. And Im actually going to use for a professional use case. Need to build something to match pictures with words.

  • @panagiotiskyriacou61
    @panagiotiskyriacou61 Год назад

    imagine that when drop widget tothe left create different categories that group the widget. So also the category component is a drop target. It is possible the category (drop target)be also a draggable item so you can merge two categories?

  • @Ayush_Bob
    @Ayush_Bob Год назад

    That was suprisingly easy thanks a lot and easy to build upon

  • @pauloricardomaltaleal3558
    @pauloricardomaltaleal3558 5 месяцев назад

    How can i pick the position when drop, according to dimensions of father component?

  • @jorims8537
    @jorims8537 Год назад

    nice idea with using the state and just appending elements. However, the usecase for this is very limited. If the position (order) matters in which I would drag my element in, it would obviously not work.

  • @vydikvaidya654
    @vydikvaidya654 Год назад +1

    Can I know how to display the HTML code for the item when it's dropped

  • @GabrielWis
    @GabrielWis Год назад

    Hi ! I have a problem. When I writing ([]) at state, show error "string is undefined".

  • @r1nzai
    @r1nzai Год назад +1

    I'd rather use react-beautiful-dnd which is used internally for trello and jira as well, and is like super easy to implement

    • @keifer7813
      @keifer7813 Год назад

      What's the cost though? In terms of bundle size and page speed?

    • @Victor-dt1uq
      @Victor-dt1uq Год назад

      It is no longer maintained though :(

  • @tiktalk4573
    @tiktalk4573 6 месяцев назад

    Thanks this is useful for us!

  • @ArynKr
    @ArynKr Год назад

    Loved it... Btw what color scheme are you using on vs code?

    • @WebDevCody
      @WebDevCody  Год назад

      bearded theme stained blue

    • @ArynKr
      @ArynKr Год назад

      @@WebDevCody Thanks 😀

  • @saladin_advanced
    @saladin_advanced 2 месяца назад

    It's kind easy finally. thx.

  • @juanorjuela7161
    @juanorjuela7161 8 месяцев назад

    Hello, I really liked your video. I would like to know if there is a repository where I could see the code better or collaborate since a couple of ideas occur to me.

  • @omomer3506
    @omomer3506 Год назад

    Nice, but something i didnt catch, the e.datatranfer carries the actual widget with all of its properties and styles? Ir is something else going jn

    • @WebDevCody
      @WebDevCody  Год назад

      It might have a reference to the underlying dragged element, but it’s more for setting custom metadata you can use later when dropping

  • @eip408
    @eip408 Год назад

    Awesome stuff! I was also looking for a way to do this drag n drop functionality because I was doing a personal project like shopify customizer. Thanks!

  • @ameen8891
    @ameen8891 5 месяцев назад

    Thanks BRoo

  • @hellome3046
    @hellome3046 5 месяцев назад

    thank you very much

  • @Tregadbm
    @Tregadbm Год назад

    Wait, how are your elements fully opaque while dragging and animate back on unsuccessful drag?
    Could it be your browser? I'm using chrome.

    • @WebDevCody
      @WebDevCody  Год назад

      Must be built into the browser because I didn’t add styles

  • @criztiandev
    @criztiandev Год назад

    Hi I just want to ask, how about free drag, could you make a video about it ?

  • @deepmane5845
    @deepmane5845 2 месяца назад

    locally it is easier how about on server
    save newly formed/droped data to sever but it takes time
    meanwhile on ui it happens quickly so
    my app is todo app in which task are divided such way that complete and incomplete
    if i drag incomplete task to complete it changes data to true on server using redux
    but on ui it takes time to load again how to deal with my app i hope you understand

  • @dr.livesey5157
    @dr.livesey5157 Год назад

    Thanks!

  • @SMTarcisio
    @SMTarcisio Год назад

    Hi, I'm from Brazil, I'm new in Javascript and React Js, cool video, so perfectly understandable but I'm trying to make a different thing, an image be drag n drop inside a div and this div has limit of the corners, when the user drag it around off limit of the corner it brings the image back to limit of the div without any package, can you help me with this?

    • @WebDevCody
      @WebDevCody  Год назад

      I’m not sure I don’t work much with drag and drop

  • @amirshaban7115
    @amirshaban7115 Год назад

    Could someone help me out with making it functional with touchEvents instead of dragEvents?

  • @waytonirvana6426
    @waytonirvana6426 Год назад

    clean and helpfull thank you

  • @chesterxp508
    @chesterxp508 10 месяцев назад

    GoodJob!

  • @micheledibe
    @micheledibe Год назад

    Nice tutorial, well explained, although this implementation, which the native Drag&Drop,
    is pointless since since is not supported on mobile devices.
    In other words, lets be honest, we gonna need third party libraries for ever 😂

  • @appstuff6565
    @appstuff6565 Год назад

    How can we store this new arrangement in a database so it persists?

    • @appstuff6565
      @appstuff6565 Год назад

      you loved the vcomment but can you please guide on something, i am building a linktree clone as a study learnning and i have tables users and links, i fetch links from supabase for that particular user. My main issue is when i fetch links i want them to be fetched as i arrange them in the list. How do i persist that? Thanks.

  • @artistry7919
    @artistry7919 Год назад

    How can we make a drag and drop feature keyboard accessible?

    • @WebDevCody
      @WebDevCody  Год назад

      Not sure, maybe enter to select the item, then left and right arrows to move it around between drop zones?

  • @CaliburPANDAs
    @CaliburPANDAs Год назад +1

    Have you tried React dndkit?

  • @ZeNiTh_2K
    @ZeNiTh_2K Год назад +1

    Out of context but which VS Code theme is that ?

    • @WebDevCody
      @WebDevCody  Год назад +1

      Bearded theme stained blue

  • @DekanTrue111
    @DekanTrue111 Год назад

    Well does it work with touch?
    In the past I have had to use react dnd with two logic handlers. Is this not needed anymore?

    • @WebDevCody
      @WebDevCody  Год назад

      Oh I didn’t try with touch, good point

  • @oguzhan2393
    @oguzhan2393 Год назад

    how can I drop the div whereever I want.

  • @muhammad-shahin
    @muhammad-shahin 10 месяцев назад

    can I get this code? did you upload it on github?

  • @jittojoyes7533
    @jittojoyes7533 Год назад

    Are you using any package here, like react dnd

  • @oddsquadd
    @oddsquadd Год назад

    the issue is that it is not working with mui icons

  • @appstuff6565
    @appstuff6565 Год назад

    but how do you persist this?

  • @umargulzar2982
    @umargulzar2982 Год назад

    can you please provide GITHUB link for source code?

    • @WebDevCody
      @WebDevCody  Год назад

      sorry I don't think I have it, it's too much work for me to upload code for every single video. Just learn what I taught and re-implement is my suggestion.

  • @anagocode
    @anagocode Год назад

    is this react-dnd or react-beautiful-dnd ?

    • @WebDevCody
      @WebDevCody  Год назад

      This is just html events I think

  • @shubhampawar7921
    @shubhampawar7921 Год назад

    Doesn't work on mobile though.

  • @SeibertSwirl
    @SeibertSwirl Год назад +1

    Good job babe!! Also first!

    • @WebDevCody
      @WebDevCody  Год назад

      thanks babe! you're back getting first place comments again

    • @YuriC.
      @YuriC. Год назад +1

      That's not fair, she knows when a video is about to drop 🧐

    • @WebDevCody
      @WebDevCody  Год назад +1

      @@YuriC. insider trading 😂

  • @someunknowngirl7208
    @someunknowngirl7208 Год назад

    Very basic and odd example specially when u do setWidgets and spredding state instead of using cb with prev param

    • @WebDevCody
      @WebDevCody  Год назад

      How’s that odd? You don’t need the callback anytime you update state

  • @muruga3603
    @muruga3603 Год назад