Solving a practical intermediate react interview challenge

Поділитися
Вставка
  • Опубліковано 26 вер 2024
  • 💬 Discord / discord
    🔔 Newsletter eepurl.com/hnderP
    📁. GitHub github.com/cod...
    My VSCode Extensions:
    - theme: material community high contrast
    - fonts: Menlo, Monaco, 'Courier New', monospace
    - errors: Error Lens
    - extra git help: Git Lens
    - tailwind css intellisense
    - indent rainbow
    - material icon theme
    - prettier & eslint
    - ES7+ React Snippets

КОМЕНТАРІ • 117

  • @pepperdayjackpac4521
    @pepperdayjackpac4521 Рік тому +112

    I watched this video entirely in my bed, and now I plan on practicing this for myself once I get out of bed. This was very interesting and helpful.

  • @Thassalocracy
    @Thassalocracy Рік тому +32

    11:26 A suggestion, the element might work perfectly as it has its own dropdown. You can nest the children inside without having to depend on a toggle state and semantic HTML is a plus.
    Anyway, thank u so much for showing us how to tackle an intermediate react challenge. 😀

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

      Great suggestion, and it seems supported everywhere.
      You had something like that in mind ?
      function Entry({name, children}: TEntry) {
      return
      {children ?
      {name}
      {children && {children?.map(value => )}}
      : {name}}
      }
      I tested it and it does the job, no need for a button and such, great thinking !

  • @JoaoVitor-gm2yf
    @JoaoVitor-gm2yf Рік тому +24

    5:58 I think it doesnt really need to keep track of depth, just use margin instead of padding, so it renders the indentation in relation to the parent element

    • @rowancode
      @rowancode 9 місяців тому +1

      This is actually great

  • @alanthomasgramont
    @alanthomasgramont 2 місяці тому +4

    IMO you don't need depth. Your child list could be a containing and that could be styled with a margin. The is also good for screen readers, where would be a list and the would be a role listItem. Also, if you are using expanding content, accessibility needs aria-expanded set.

  • @aamiramin6112
    @aamiramin6112 Рік тому +5

    This is so informative and real-world use cases like recursion, rendering, etc. Thanks alot for sharing.

  • @BrooUmad
    @BrooUmad Рік тому +9

    I love watching you code man. I interned at a place last year using React and I was really bad at that. Watching you is making me want to try again with front end.

  • @skapha
    @skapha Рік тому +5

    WDJ this is awesome! Please more of this kind of content, more challenges (intermediate to advanced)!
    The Essence!

  • @TheLorepRocks
    @TheLorepRocks Рік тому +11

    I had to do a similar code challenge, but also I had to add an input next to every element in the tree after pressing the enter key the child should be added to the right tree level. I haven't received any feedback but looking at this video makes me feel like I did a good job! Thank you! :)

  • @csy897
    @csy897 Рік тому +4

    Thanks so much! I was about to give up leetcode because I didn’t understand the need for data structures beyond maps and arrays like trees, stacks, heaps as a frontend dev. But you just showed an elegant solution with recursion. Gives me good motivation to study more!

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

    You don't need depth prop, with ol > li and padding does works

  • @BigKaTrob
    @BigKaTrob Рік тому +3

    Nice, I like the way you handled the depth. This could also be done in CSS with a clever use of a sibling selector but I like the way you've done it here with js a little better.

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

    Nice video. This gives me a lot of confidence if this is intermediate / advanced. Im only about a year into my first dev job but I could pretty easily come up with a solution for this.

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

    Dude, love your videos. I always watch them before I go to bed to wake up first thing in the morning and practice on them 🤙

  • @kelechi.E
    @kelechi.E Місяць тому

    You made this look super easy!

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

    Button was not needed I think, could do the trick

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

    Never was a person to comment on a youtube video, like or share it. But these types of coding for intermediate react js interview qsn made me do all those things.

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

    tks dude, u help a lot with this code challenges series, i've never had think to use recursive code to render a component.

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

    im a mid full stack dev and still great to see someone eleses thinking process. Grat content!

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

    Thanks for the great content, as always, Cody!

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

    These are the best! Please keep these coming!

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

    Thanks 🙏🙏... This is exactly what i was gonna work on and your way is so much simpler

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

    Loving this series and get learn something new before going to bed. 👍🏽

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

    for the styling of the button you can use something like ->
    button {
    all: unset;
    cursor: pointer;
    }
    then it will remove all the default stylings

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

    This is some kind of content that is not available and really fun to watch

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

    Appreciate this video! Just been given a project at work to design a section based hierarchy like this (ex. 1.0, 1.1, 1.1.2, …). Now just need to think about how to create subsections under the parent that line up with backend

  • @eshw23
    @eshw23 10 місяців тому

    Hey cody nice video! Next time for future code challenges can you maybe just give a bigger in depth explanation of the problem, with more examples, I didnt understand the problem at first or what it should look like(maybe im stupid😀), Thanks!

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

    Awesome :D really enjoyed this!

  • @memeproductions4182
    @memeproductions4182 Рік тому +3

    Little late lol, but you don't need to add 10 padding * depth for esch node, since every node has already the cumulative padding of the previous levels. Otherwise your children will have always increasing padding compared to the previous ones

  • @UltraKillpc
    @UltraKillpc 5 місяців тому

    Many things to learn here

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

    This was super helpful!

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

    Amazing explanation

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

    very good exercice
    thanks a lot

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

    more of these kind of videos please!

  • @yahwehagape
    @yahwehagape 7 місяців тому

    Instead of mapping over files in App component, just have a root Entry and when you nest it in App no need to reimplement mapping there.

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

    Can bypass much of the react complexity by using and HTML tags

  • @Daddyjs
    @Daddyjs 6 місяців тому

    Beautiful

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

    this is interesting.
    Just recently i coded a Dynamically increasing tree. - to allow fetching additional folder data from subfolders and not loading everything at once.
    Used a "Path" Variable, splitted it by "/" and used a recursive function to recursivly call itself until the splitted path is empty, returning the data.
    It looks super weird in code. But i think i got a quite good solution.

  • @vanovasilyan3807
    @vanovasilyan3807 9 днів тому

    Thanks 🤝💪

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

    thank you

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

    Awesome video

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

    What if files was just an array of objects instead of files being an object with the children key ?

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

    I have a year 2months of experience as full stack developer and I just applied for a job that required 3 years of experience as frontend developer
    the phone screen was ok and they move me to the next role
    how do I prepare it in one week ?
    I will appreciate any advice here

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

      Idk that’s a hard one. Fake it till you make it

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

    How can we adapt this solution to keep track of which sub-folder has been opened, and keep that state persistently, even though the parent folder has been closed and then reopened?

  • @livetowin-pj7yl
    @livetowin-pj7yl Рік тому

    I don't even know where to start with kind of problem. Thanks for enlightening me. Though I know recursion and why you used it here, is it required to know DSA at this point?

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

    Hi Cody, I tried to build a tree using recursion and I was successful, however when I implemented a search algorithm to filter in the tree. I faced this invariant violation- rendered fewer hooks than expected. and now I am not able to move forward

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

    very interested in this

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

    how to setup auto complete optional chaining?

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

    thanks really helpful. for this video do you practice it beforehand or straight live coding? thats awesome if it is live coding

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

      I just start with the idea and start coding

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

    Don't forget to add some maximum depth to prevent infinite recursion

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

    It would be more easier if you used the details tag of html, don't you think?

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

    good one

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

    how to do you switch to the browser behind the vs code and the mouse stays on the same position?

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

      do you mean the built in virtual monitors mac os provides?

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

    13 min video to make that, probs a good hour for me😂 (I'm a beginner btw)

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

    Where do you get these react challenges? Or do you just randomly think about it or came across it

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

    How does the isExpanded && () work?

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

      If isExpanded is truthy it’ll render the next part out to the screen

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

    I aspire to someday be a Frontend Developer (never applyed to jobs cause i didn't study cs and feel like I'm not enough).. and when I saw that this is Intermediate I feel like I'm already a "Senior" cause this looks pretty easy to me.. So my question is, how much should I ask for when I get an offer? :)

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

      The intermediate is all relative. Your starting rate would probably be the average for your country and area for a junior dev if you never had a coding job. Again, these challenges are just to verify you can at least code and problem solve, there would still be a lot of questions and discussions that might happen before or after any coding challenge.

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

    There's an html tag called details that would've been better suited for this

  • @algorithmictoolbox6856
    @algorithmictoolbox6856 7 місяців тому

    This is what i was asked yesterday, and i solved it after the interviewer was gone

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

    From.where do u find these questions is there any website for daily react js challanges

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

      I usually make them up

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

      @@WebDevCody will u make more like 30 days challenge from biggner to advance please it will help a lot for interview for a Fresher like me

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

    Is this consider intermediate/advanced? I believe there must be harder questions than this that are for begginers

    • @cszqravr
      @cszqravr 8 місяців тому +1

      Yeah, this definitely is an very, very easy one. We would only use such an example if the candidate is super nervous to hand them a free win and move on to an actual coding interview. Even with that being the case, the shown solution definitely would be docked some points

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

    Is vite better than yarn? or whats the diference between them?

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

      They are different tools. Vite is similar to webpack and it’s used for bundling your code. Yarn is similar to npm and is used for managing project dependencies

  • @warzonehacks4915
    @warzonehacks4915 10 місяців тому

    Can someone tell me where he used the recursion?

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

      The function entery has
      a component entry that references the entry function. You can see that entry references itself. This is recursive as it will continue to call entry on the stack until there is no more children, which is our base case, and then we exit returning entry.

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

    Hi where do you get your practice questions from?

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

      Other people and I make some up

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

    i think there is a tiny bug in your isExpanded logic.If u click the button all other files expanding ,in my opinion expanding state must be unique for all parent files and toggle it individually.

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

      I don’t see the bug, joi isn’t expanded when node_modules is expanded

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

      ​@@kris24_lawson yes you are right there is no bug at all cause of the every time new component render and it has a prop individually

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

      @@gorkemeldeniz9579 would you please go into more detail? I initially thought the same thing as your first comment.

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

      @@alexluu3615 if the parent component share expand state as a prop to children it effects all other child components but he make the statement in the children component therefore it does not effect each other all states are individual

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

      @@gorkemeldeniz9579 thank you for your response and helping clear the confusion. best of luck to you and your coding journey!

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

    nice

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

    Nested drop-down list?

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

    Amazing!
    Just speak a bit slowly and up please.
    Not only native english speakers watch you!

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

    Typescript does seem a lot of extra boilerplate and work

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

      In small project sure it might seem so, but as it gets bigger advantages are far more visible

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

      It’s useful, I promise

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

      The problem is that I see a lot of videos where there is all this extends, typeof, generic, , and it all looks confusing.
      A good example would be the youtuber Matt Pocock, he is supposed to be a typescript wizard and he does all this stuff with it and it is a little daunting to us beginners

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

      @@SahraClayton Most of the 'generic sorcery' makes the code really hard to read for TS beginners but it shouldn't discourage you from utilizing structural typing in your codebase.

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

      ​@@SahraClayton ​Well ts typesystem is basically a new language on top of a javascript so you simply have to learn it to understand more complex stuff with generics

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

    hello bro, my question is out of the topic but does RTK still makes sense with NextJS 13 app directory? or any state management you suggest to be use?

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

      I like jotai right now. Super simple to setup and share state between components.

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

    123

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

    Get well soon, Web Dev Junkie 🙏🤗.
    Thanks for the video 🍉😉👍!

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

    Bro can you make better title?

    • @McProski
      @McProski Рік тому +4

      what's wrong with the title lol?

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

      I think he's distrete with his titles to prevent people from easily searching for the solution when prepping for coding interviews.

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

      What would you recommend the title being?

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

      @@mjohnson510 actually i didn’t think of that, but that’s a good reason. I figured having “intermediate interview challenge” would bring more views than “building a file tree viewer in react”. People like prepping for interviews, they don’t care about building a tree browser 😂

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

      @@WebDevCody I actually got the File Structures problem from Atlassian lol.
      But, I like your titles. I actually search React Intermediate/Advanced interview problems then the actual specifics

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

    I just wanted a simple mockup tree from an acual folder and came up with this in PowerShell, you do however need to pipe it to "Convertto-Json -depth 100" after to format it correctly.
    function Get-HTMLFileTree($dir) {
    $folder = Get-Item $dir
    $html = [System.Collections.ArrayList]@()

    $obj = [PSCustomObject]@{
    name = $folder.name
    }
    if ($folder.Mode[0] -ne 'd') { $html.Add($obj) | Out-Null; return $html }

    $obj | Add-Member -MemberType NoteProperty -Name children -Value ([System.Collections.ArrayList]@())
    $children = $folder | Get-ChildItem
    foreach ($child in $children) {
    $obj.children.Add((Get-HTMLFileTree -dir $child.FullName)) | Out-Null
    }
    $html.Add($obj) | Out-Null
    return $html
    }
    (ex. Get-HTMLFileTree -dir . | Convertto-Json -depth 100 | Set-Clipboard)

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

    That's called accordion and it is an easy one

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

    I think one optimization... it's possible without the nested mapping. Remove the initial mapping and pass 'entry.children' directly into then mapping there, while checking 'entry.children && ' to trigger the recursive.
    any who, thank you for this challenge! watched the video and jumped on the computer like "YOU CAN RECURSIVELY RENDER?!"

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

    This was actually pretty straightforward, I expected it to be harder for an intermediate challenge. I feel like my imposter syndrome often acts up but most of these challenges end up being a breeze. Time to start applying for more senior roles I guess.