Must Know React Portability Patterns

2024 ж. 17 Мам.
25 297 Рет қаралды

Learn to architect React apps that work across NextJS, Vite, etc. while still accessing the advantages of those platforms. To try everything Brilliant has to offer-free-for a full 30 days, visit brilliant.org/JackHerrington/ . The first 200 of you will get 20% off Brilliant’s annual premium subscription.
Code: github.com/jherr/portable-rea...
👉 I'm a host on the React Round-Up podcast: devchat.tv/podcasts/react-rou...
👉 Don't forget to subscribe to this channel for more updates: bit.ly/2E7drfJ
👉 Discord server signup: / discord
👉 VS Code theme and font? Night Wolf [black] and Operator Mono
👉 Terminal Theme and font? oh-my-posh with powerlevel10k_rainbow and SpaceMono NF
0:00 Introduction
1:30 Example Next JS Application
2:15 Architectural Win Of Monorepos
11:34 Uncoupling The Detail Page
14:50 Creating The Environment Context
17:52 The Power Of An Environment Context
18:43 Extracting The Search Page
24:30 Reusing Everything In A Vite App
32:09 How We've Unlocked Vendor Lock In
This video was sponsored by Brilliant

Пікірлер
  • To try everything Brilliant has to offer-free-for a full 30 days, visit brilliant.org/JackHerrington/ . The first 200 of you will get 20% off Brilliant’s annual premium subscription.

    @jherr@jherr Жыл бұрын
  • Great video as always Jack. Learned a lot! I really appreciate more senior level content that you provide.

    @_leszcz@_leszcz Жыл бұрын
  • Would you like to create some cool stuff about React Native?

    @najlepszyinformatyk1661@najlepszyinformatyk1661 Жыл бұрын
  • I like how it's straight to the point, no extra data.

    @anasouardini@anasouardini Жыл бұрын
  • Great as always. I would love to see this with the combination of Expo + NextJS using Tamagui 🙂

    @user-py1ti1lf8u@user-py1ti1lf8u Жыл бұрын
  • So good! Thanks for sharing this pattern. I've known the reasons for why this is useful, but it is good to see a practical example showing the exact abstractions used in this architecture.

    @sprioleau@sprioleau Жыл бұрын
  • Nice decoupling tips! Definitively agee with this, not used enough. Some other fancy decoupling ideas I had: - inject hooks as context, decouple from React-Query etc: useApp().useMyQuery() - use webpack/bundler aliases for components: "app/link" => "next/link" - use extensions for DI like RN: Link.next.tsx + Link.remix.tsx - extend React DOM renderer to support a custom link element 🤔

    @thisweekinreact@thisweekinreact Жыл бұрын
    • I think the aliases trick is what is used for React native web ^^

      @Septrba@Septrba Жыл бұрын
  • Jack, as a junior React/TS dev, I really appreciate your content. You are pretty much my go-to source of the aforementioned tech. Just want you to know how much you are helping us out in the community. Appreciate your effort.

    @marcuslorenzo9705@marcuslorenzo9705 Жыл бұрын
  • Great video! First time seeing these concepts so well explained and with examples. Thanks for sharing, highly appreciated and highly educational.

    @edvargas18@edvargas18 Жыл бұрын
  • My team is currently evaluating what to replace CRA with. This content is incredibly timely, and I'll definitely reference it when migrating our app. Cheers!

    @falldowngoboone@falldowngoboone Жыл бұрын
  • Felt very relatable, as i've recently ported a mid size nextjs app to react. Took me about 30days & some help from seniors.

    @tapank415@tapank415 Жыл бұрын
  • This was awesome. Thanks for enlightening me. I made a Vite/Vue app as a passion project late last year. Now I know how to structure things on my next project or when I update it!

    @ExonerativeKoala@ExonerativeKoala Жыл бұрын
  • Golden video that shows how to do dependency injection with react context like we have in angular apps. Saved the day

    @cacup7@cacup7 Жыл бұрын
  • Nice one! 3 things i would add: - Extract the Provider logic to a component in the lib package - Extract the hook to the lib package as well - For the data fetcher i would just return the data and on the next app past in {props} object on getServerSideProps

    @victorlongon@victorlongon Жыл бұрын
  • I loved the video. I've used that technique of sharing React components through context but I always felt it was like an anti-pattern. Glad to see it wasn't such a bad idea.

    @Dgiulian@Dgiulian Жыл бұрын
  • Awesome content Jack, thank you! Question: how would you implement authentication+authorization in a setup like this? I struggle a lot in 'hybrid' situations where an external idp like auth0 is used, and role based authorizations based on JWT on *both* frontend and backend (SSR) are needed. Would be awesome to see how you would approach authorization schemes in a setup like this monorepo.

    @bastiaanschaap@bastiaanschaap Жыл бұрын
  • I'm happy, when Jack is happy!

    @BalaevArif@BalaevArif Жыл бұрын
  • Love these unusual more advanced topics

    @dog4ik@dog4ik Жыл бұрын
  • Great video Jack. Thank you for sharing it. Your approach is really practical and I love it. In fact, it doesn’t like the way in that people start from scratch with diagram, UML.. to design a new application. Could you please create another video which describes this problem with “theory approach”?

    @vuluu4066@vuluu4066 Жыл бұрын
  • I essentially did this same thing, but at a component level. I think I may rethink some things and extract my application even more so that Next is not a hard requirement.

    @digioi@digioi Жыл бұрын
  • Awesome video! Thank you Jack

    @sobrevivendo-no-front@sobrevivendo-no-front Жыл бұрын
  • Amazing video as always Jack! ❣️

    @CarlosAlexisG@CarlosAlexisG Жыл бұрын
  • Thank you so much for another great video! I've learned some new tips today about the Environment Context approach! It's good to see you are using Nx in this demo. I'm hoping one day you will be back with some more videos on the MFE and MF, I'd love to see how you would structure multiple apps, one with static code sharing, others with dynamic code sharing, between different bundler Webpack and Vite and possibly the host app written in Nextjs if that is possible?

    @michaelta05@michaelta05 Жыл бұрын
    • Also another way to quickly identify the code sharing paths is by looking at the tsconfig.base.json in the nx project root...

      @michaelta05@michaelta05 Жыл бұрын
  • great video, thanks for makong them

    @peteradam4740@peteradam4740 Жыл бұрын
  • Great video, thanks! If you add a React Native App, you would add the basic elements (View, Text, etc) to the Environment Context?

    @thecodecatalyst@thecodecatalyst Жыл бұрын
  • Hi Jack, thank you for another great video. Learned a lot of new things. On a side note which theme are you using for your VSCode? It looks so clean with the font.

    @MahbuburRahman-uc7np@MahbuburRahman-uc7np Жыл бұрын
    • JETBRains Mono and Night Wolf [black]

      @jherr@jherr Жыл бұрын
  • Excellent video, really useful info.

    @bartgrundeken1428@bartgrundeken1428 Жыл бұрын
  • Jack Herrington => G.O.A.T

    @KiloSierra1@KiloSierra1 Жыл бұрын
    • For real. His contributions to public content are incredible.

      @zachomis@zachomis Жыл бұрын
  • 14:50 I wonder whether this is another case of developer convenience imposing a runtime cost when the maintenance concern could be addressed with a build time solution. The capabilities that a capacitor/web application encounters are not going to vary for the duration of the application session so it really doesn't seem like a runtime concern (i.e. a case for late binding). Granted this is just a standard case of runtime dependency injection but maybe there is a better way; an environment module. Configuring the build tooling to resolve to the correct implementing module (e.g. rollup/plugin-alias ) may be a bit more hassle but it would remove the runtime indirection of retrieving the component repeatedly from the context. [PHP Frameworks Day 2013 [eng] / Rasmus Lerdorf; 31m49s]

    @peerreynders1824@peerreynders1824 Жыл бұрын
  • Really awesome and informative learned a lot🔥. Prior to watching the video, I had some confusion about the differences between module federation and Monorepos (using Nx). However, this video provided much-needed clarity. my team is currently in the process of merging two Next.js projects - one of which utilizes Redux while the other utilizes Context API. I will definitely discuss this pattern with my team. btw any thoughts how we can go about this?

    @abhishekvishwakarma9045@abhishekvishwakarma9045 Жыл бұрын
  • Hi Jack! Thank you for the content, you rock! Do you think that is a good practice to share code between different apps in a monorepo? Will that not make the changeability of the apps more difficult? In what cases it is recommended to share? Thanks!

    @javiervazquezfernandez1872@javiervazquezfernandez1872 Жыл бұрын
    • Actually the reason you want code in a monitors is to maximized reuse. So absolutely it’s a good idea to share code in a monorepo. That being said the sharing should be between apps and packages and not directly between apps. So if you have something to share the extract it into a library package and the import that into any consuming applications.

      @jherr@jherr Жыл бұрын
  • Great patterns! Thanks.

    @robbiedelavictoria@robbiedelavictoria Жыл бұрын
    • Thank you so much!

      @jherr@jherr Жыл бұрын
  • These videos give me brain tingles :D

    @nattysweg343@nattysweg343 Жыл бұрын
  • Environment Context reminds me a lot to the Strategy Design Pattern :0

    @Weagle1337@Weagle1337 Жыл бұрын
  • Great video and a nice pattern for people to learn, especially as all the big React frameworks get snapped up by large vendors that want to keep you on their platform. Just curious, do you think this could be extended to work with Qwik and the qwik-react plugin?

    @IainSimmons@IainSimmons Жыл бұрын
    • Definitely. There are lots of ways to reuse logic, and yes, in the case of Qwik, even React components.

      @jherr@jherr Жыл бұрын
  • One thing I would be interested in would be whether you could do this with a completely different framework, like vue or svelte instead of another type of react app.

    @lifeofdandotme@lifeofdandotme Жыл бұрын
  • Great stuff. Wondering how to register that ui lib to npm 🎉

    @huuthongle8768@huuthongle8768 Жыл бұрын
    • I think they make it fairly easy to npm publish.

      @jherr@jherr Жыл бұрын
  • You spoke about react native. How can we reuse the components and maybe pages on both systems? I am thinking mainly of styling differences.

    @akosbalint3485@akosbalint3485 Жыл бұрын
    • react-native-paper? basically just sit on a bunch of stylable components that are alreay react/react-native.

      @jherr@jherr Жыл бұрын
    • @@jherr Thank you, I will look into it.

      @akosbalint3485@akosbalint3485 Жыл бұрын
    • I am thinking of using your Environment Context pattern and somehow transform tailwind classes in react app to components in react-native app.

      @akosbalint3485@akosbalint3485 Жыл бұрын
  • I like the idea of using a context as a sort of depdendency injection, but unfortunately contexts won't work at all in React server components. Is there a way to make the concept work there? For example, in the NextJS app directory?

    @IAmLesleh@IAmLesleh Жыл бұрын
    • A singleton with a setter in the top level layout would do the trick.

      @jherr@jherr Жыл бұрын
    • Good observations Leslie, brings quite some to the topic, I believe deeper you get into more complex app, decoupling like presented becomes much more challenging. To the point that maintaining it without any clear direction for the product to change framework could be questionable

      @loginorc@loginorc Жыл бұрын
    • This is why we need a standardized AsyncContext (TC39 stage 2 proposal): possibility to implement cross-platform context that works for server/client in the same way!

      @thisweekinreact@thisweekinreact Жыл бұрын
    • @@thisweekinreact Hmmm, yeah, good one. One question is whether we expect it to be changing over time. If not then it should be. And in the case of Link, for example, that won't change for the lifetime of the app.

      @jherr@jherr Жыл бұрын
    • @@jherr For static elements that makes sense yes But a Link in a SPA is often an interactive component to intercept click events and navigate, so you could just make your link wrapper a client component and use a context like you show in this video ;)

      @thisweekinreact@thisweekinreact Жыл бұрын
  • Would you suggest using Lerna or NX for monorepos?

    @mdmathewdc@mdmathewdc Жыл бұрын
    • NX, Lerna is no longer being maintained AFAIK.

      @jherr@jherr Жыл бұрын
  • great content😉

    @thiagomoraes791@thiagomoraes79111 ай бұрын
  • The Environment context concept looks like the Adapter pattern but in a monorepo?

    @SpaghettiRealm@SpaghettiRealm Жыл бұрын
    • It’s totally the adapter pattern, you nailed it.

      @jherr@jherr Жыл бұрын
    • @@jherr Thanks Jack, we learn a lot from you, great content 💙

      @SpaghettiRealm@SpaghettiRealm Жыл бұрын
  • I dont like css-in-js at lib level, what are the alternatives for styling but dont get locked in, for lib?, I.e Using emotion has a runtime cost, and I want to choose a other way, but this means a big refactor all the way from libs to apps

    @nvucuong@nvucuong Жыл бұрын
  • Please create the series on React Router Dom v6 It's overwhelming

    @AzharUddin-ob7vb@AzharUddin-ob7vb Жыл бұрын
  • brilliant

    @marccavada5434@marccavada5434 Жыл бұрын
  • Hey Jack, are you still using zustand? And if so, what are you thoughts of making a zustand tutorial any time soon?

    @bekirs4240@bekirs4240 Жыл бұрын
    • 100% using it. A tutorial on it... Sure?

      @jherr@jherr Жыл бұрын
    • @@jherr yeaaaaa, nice

      @bekirs4240@bekirs4240 Жыл бұрын
  • Great video! Frameworks make it so easy for us to use their patterns. But they are very opinionated.

    @AngelEduardoLopezZambrano@AngelEduardoLopezZambrano Жыл бұрын
  • quick question: how is there a search bar on the header of your vscode? I am on windows on don't get it

    @nexusdino4374@nexusdino4374 Жыл бұрын
    • editor.stickyScroll.enabled ?

      @jherr@jherr Жыл бұрын
    • @@jherr Sorry Jack, its not working

      @nexusdino4374@nexusdino4374 Жыл бұрын
    • @@nexusdino4374 Yeah, I don't really know what specifically you are talking about, so I took a guess. Feel free to jump on the Discord server and ask there but please READ and FOLLOW the #rules before posting.

      @jherr@jherr Жыл бұрын
    • @@jherr Found it out, it's windows.commandCenter, ty for help

      @nexusdino4374@nexusdino4374 Жыл бұрын
  • I know this is an example app, but just for the guys that saw it. The pokemon filter should be done in the API, not in the frontend ok? Send the parameters via the request, then get back specific what you need.

    @joaobibiano@joaobibiano Жыл бұрын
  • Hey Jack , a small remark .The visibility in mobile is not very good. Font is small and the color is also a bit dark so its hard to follow along in mobile when you explain the folders files and code themselves . Thanks

    @vijaykrishna7231@vijaykrishna7231 Жыл бұрын
  • Your background is really awesome is it real 😐

    @zahirshaikh3535@zahirshaikh3535 Жыл бұрын
    • Yeah, that's my office. It is a green screen though since I want to be able to record at any time of day.

      @jherr@jherr Жыл бұрын
  • Great! Now can we see how to use in React Native? Sure, why not, right? Well, that's not gonna be as simple, but maybe we can give it some work? 😃

    @mladenknezovic7410@mladenknezovic7410 Жыл бұрын
  • Sir plz make tutorial on react or Next 13 pl

    @usmanmarkaz@usmanmarkaz Жыл бұрын
  • nx!!!!!! yes!!!!!

    @Balance-8@Balance-8 Жыл бұрын
  • pokemon 👍

    @Dev-Siri@Dev-Siri Жыл бұрын
  • Make react or next js course 25-50 dollars

    @michaelscofield2469@michaelscofield2469 Жыл бұрын
  • One of the reasons why I keep myself from learning JS frameworks, vendor lockin bs.

    @socialkruption@socialkruption Жыл бұрын
  • *uses react* *talks about fighting lockin*

    @purpinkn@purpinkn10 ай бұрын
KZhead