Solving a practical intermediate react interview challenge

Поделиться
HTML-код
  • Опубликовано: 15 ноя 2022
  • 💬 Discord / discord
    🔔 Newsletter eepurl.com/hnderP
    📁. GitHub github.com/codyseibert
    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

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

  • @pepperdayjackpac4521
    @pepperdayjackpac4521 Год назад +92

    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.

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

    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!

  • @Thassalocracy
    @Thassalocracy Год назад +26

    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 3 месяца назад

      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 !

  • @TheLorepRocks
    @TheLorepRocks Год назад +10

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

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

    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.

  • @skapha
    @skapha Год назад +3

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

  • @BrooUmad
    @BrooUmad Год назад +8

    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.

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

    Thanks for the great content, as always, Cody!

  • @JoaoVitor-gm2yf
    @JoaoVitor-gm2yf 10 месяцев назад +16

    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 4 месяца назад

      This is actually great

  • @aamiramin6112
    @aamiramin6112 Год назад +5

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

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

    These are the best! Please keep these coming!

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

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

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

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

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

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

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

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

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

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

    Awesome :D really enjoyed this!

  • @nikhilbhagat3832
    @nikhilbhagat3832 7 месяцев назад

    Amazing explanation

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

    Button was not needed I think, could do the trick

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

    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

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

    more of these kind of videos please!

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

    This was super helpful!

  • @bradaa2053
    @bradaa2053 9 месяцев назад

    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 4 месяца назад

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

  • @mandalorian99
    @mandalorian99 7 месяцев назад

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

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

    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!

  • @gabrielfono844
    @gabrielfono844 11 месяцев назад

    very good exercice
    thanks a lot

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

  • @honournosa9129
    @honournosa9129 11 месяцев назад

    Awesome video

  • @Daddyjs
    @Daddyjs Месяц назад

    Beautiful

  • @user-pi2zd4xj8z
    @user-pi2zd4xj8z 28 дней назад

    Many things to learn here

  • @rishilapsiwala9503
    @rishilapsiwala9503 7 месяцев назад

    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

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

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

  • @EvilTim1911
    @EvilTim1911 7 месяцев назад +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.

  • @medAmineRg
    @medAmineRg 7 месяцев назад

    thank you

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

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

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

    very interested in this

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

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

    good one

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

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

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

  • @gabrielfono844
    @gabrielfono844 11 месяцев назад +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  11 месяцев назад

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

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

    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.

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

    how to setup auto complete optional chaining?

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

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

  • @poloiaish6281
    @poloiaish6281 11 месяцев назад

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

    • @WebDevCody
      @WebDevCody  11 месяцев назад

      I just make them up

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

  • @IgnitedIce81
    @IgnitedIce81 11 месяцев назад

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

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

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

  • @emmanuellmiqueletti7029
    @emmanuellmiqueletti7029 11 месяцев назад

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

    • @WebDevCody
      @WebDevCody  11 месяцев назад +1

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

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

    How does the isExpanded && () work?

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

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

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

    Nested drop-down list?

  • @dailyDiary213
    @dailyDiary213 7 месяцев назад

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

    • @WebDevCody
      @WebDevCody  7 месяцев назад

      I usually make them up

    • @dailyDiary213
      @dailyDiary213 7 месяцев назад

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

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

    That's called accordion and it is an easy one

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

    nice

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

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

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

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

    Hi where do you get your practice questions from?

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

      Other people and I make some up

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

    Can someone tell me where he used the recursion?

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

      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.

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

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

    • @cszqravr
      @cszqravr 3 месяца назад +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

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

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

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

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

      ​@@kristopherlawson3893 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!

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

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

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

  • @CraigClayton-bk3ze
    @CraigClayton-bk3ze Год назад

    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

    • @CraigClayton-bk3ze
      @CraigClayton-bk3ze Год назад

      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 Год назад

      @@CraigClayton-bk3ze 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 Год назад

      ​@@CraigClayton-bk3ze ​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

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

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

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

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

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

    123

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

  • @algorithmictoolbox6856
    @algorithmictoolbox6856 3 месяца назад

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

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