React Server Side Rendering Introduction For Beginners - ReactJS ssr with Expressjs

Поделиться
HTML-код
  • Опубликовано: 1 окт 2024
  • 📘New Course: Build full-stack React Typescript applications tsreact.maksim...
    Learn how to setup basic server side rendering using ReactJS and Express.
    Follow me on Odysee: odysee.com/$/i...
    React SSR (Server Side Rendering) is a technique when you pre-render initial state of your application on backend.
    It can greatly improve user experience if used correctly.
    🐦 Twitter: / ivanov_dev
    I write about React and TypeScript there
    Code for the tutorial: github.com/sat...

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

  • @HarshSingh-hk8fe
    @HarshSingh-hk8fe 2 года назад +17

    this is the most straightforward to the point tutorial i've ever seen just amazing bro

  • @010timeboy27
    @010timeboy27 Год назад +3

    Still works. Preparing for interviews, and am looking for easy ways to implement SSR, other than NextJS.
    Side for everyone else. Your Index.js on the client-side will look slightly different to the video now:
    import { hydrateRoot } from "react-dom/client";
    const domNode = document.getElementById("root");
    hydrateRoot(
    domNode,



    );
    Happy coding

  • @kinekt2000
    @kinekt2000 3 года назад +13

    какой классный тяжелый русский акцент, чувак ты ахуенен

  • @talkohavy
    @talkohavy 3 года назад +1

    Once again, you uploaded an extremely short video, which is lacking so many explanations, and showed stuff that doesn't really work or apply on a full-scale real world applications. Why even bother with these short videos? To who this contributes?

  • @nuyi9411
    @nuyi9411 4 года назад +10

    Simple code! Love it. Could you make a tutorial how to use it along with React-Helmet? Thanks!

  • @userfpdnbknsdbmfn
    @userfpdnbknsdbmfn 2 года назад +1

    It works fine but i have a little problem. My dotenv-package isn‘t working anymore after implemented react-ssr, do have someone a Tip for me to fix it?

  • @09sangram
    @09sangram 4 года назад +5

    I am using react router and getting error when I am trying to run in SSR mode

  • @joantonio6331
    @joantonio6331 4 года назад +7

    For those who would wonder how to update the website after you edited the app, simple rebuild it then re run ssr

  • @jeromelanteri6469
    @jeromelanteri6469 4 года назад +4

    syntaxe: "node_modules" and not "node_module".

  • @densfloar
    @densfloar 4 года назад +21

    Nice. It would be awesome and then I would subscribe if you took the time to explain why you do it this way. Maybe not every line, but for instance why replacing, why installing hydrate etc

  • @gooddha
    @gooddha 4 года назад +11

    Хорошее видео, четко и по делу без лишней воды, шуток-прибауток и мычания!

    • @adhamahmed3300
      @adhamahmed3300 3 года назад

      exactly

    • @1001-w5q
      @1001-w5q 3 года назад

      @Snake ETH лично я дохуя чего не понял, но я ни разу не лез в бек, поэтому хз в ком проблема

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

    greate, but how should put it on cpanel host?

  • @atg1203
    @atg1203 4 года назад +10

    Great video! You simplified it a lot compared to some of the other articles/videos I watched for React SSR.

  • @MichaelSalo
    @MichaelSalo 2 года назад +5

    This is great thank you. I see how this renders the HTML on server side. A question is why do we want to ignore styles?

    • @baraousseni1686
      @baraousseni1686 2 года назад

      If you watch the whole video, you'll see that inside his server/index.js file at the first line he uses require('ignore-styles'); which is used just to ignore the style

    • @winnerleparadoxe6496
      @winnerleparadoxe6496 2 года назад +1

      @@baraousseni1686 Yes but ignore the style?

  • @alexon2010
    @alexon2010 4 года назад +5

    Hello, friend I liked this approach for React SSR, it is very easy to understand, but I could normally use Redux, ReactRouter and Styled-Components, you would have a video that integrates these three points (Redux, ReactRouter and Styled-Components in React SSR)

    • @AjithKumarsham
      @AjithKumarsham 2 года назад

      +1

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

      since ReactDom.hydrate simply makes the components from the client use the HTML generated from the server, it should integrate without any problem with other dependencies.

  • @Vasuchowdary
    @Vasuchowdary 2 года назад +1

    you look like theon greyjoy from game of thrones any way nice explanation

  • @zlackbiro
    @zlackbiro 3 года назад +1

    this doesent work if you have async functions in your projects... Thats means its real hell to get this setup work in this way if you have a lot of components with advanced instructions inside such promisess and async things around.

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

    Thank you so much, bro, this video is very helpful for all, and your understanding way is ossom, thanks for sharing this, I request to one thing please can you make a video to CSR to SSR in vuejs, if you do please reply me, thanks a lot.

  • @lazy-codes
    @lazy-codes 25 дней назад

    Widget-base WP Theme development Series:
    ruclips.net/video/T-ZFL9pEpa8/видео.html

  • @alexon2010
    @alexon2010 4 года назад +1

    63/5000
    It worked is that I have to run yarn build and then yarn ssr

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

    - I dont remember if it is default import
    * checks *
    no it is not,
    * checks again *
    yes it is.
    Typical developer moment 💀💀

  • @deepbaaaaaag
    @deepbaaaaaag 2 года назад +1

    🤩

  • @arturgorbunov3792
    @arturgorbunov3792 2 года назад +1

    Can you please explain how to create SSR with Routes ? Especially with Router-V6 &&

  • @taimoorfarooq8971
    @taimoorfarooq8971 3 года назад +1

    Dude, everything's great and appreciate you for the tutorial, but couple of things are bugging. First, can you make an example with the running react development server rather than build and second using this, it's giving me error that "require is not defined". please help me out with this.

  • @nitindaphale2008
    @nitindaphale2008 2 года назад +1

    If Error "React undefined", then "Import React" in every component file specially if you are using React17+

  • @akich.1782
    @akich.1782 4 года назад +1

    you look like the guy that kills John Wick's dog. joke aside this video is really helpful.

  • @sebastianossandon2532
    @sebastianossandon2532 3 года назад +1

    How do you copy an entire line without selecting all the text?
    how do you select an entire line in a mac?
    how do you copy a line declaring a function and then only change the name of the function by deleting the entire word?
    all those shortcuts man, I'm new to macOS and I don't use VSCode as much, they'd be helpful

  • @mohamethseck
    @mohamethseck 4 года назад +5

    This video is perfect! Very simple and straight to the point.

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

    That is working on local server, thanks for making it,
    but when we run npm run build, and then npm serve cmd to check dist folder is working or not, it giving me an error (Uncaught TypeError: n.createRoot(...).hydrate is not a function)
    please anyone help me

  • @rahil-aliyev
    @rahil-aliyev 2 года назад

    I think it does not work for me. Because I did everything, but when I clicked "view source page", it did not change

  • @victornikliaiev466
    @victornikliaiev466 2 года назад

    Thank you! now I have an image how to use ReactDOMServer and ReactDOM.hydrate guy :D

  • @FullStackDevGreg
    @FullStackDevGreg 2 года назад

    LocalStorage WrongReferenceError error, how can I insert normal js function,

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

    Thank you for this tutorial. Its great! How to add meta tags into the head of the pre-rendered html file, if we replace only root div?

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

    Does it still works if i put it in a diferent directory after running npm run build?

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

    Then I'll have to pass my pc to users to access it or I'll give them link to my localhost

  • @paRrrrabola
    @paRrrrabola 4 года назад +1

    Лучше конечно указать targets в preset-env чтобы бабель не трасниплил лишнего и не было проблемы с полифилами.
    require('@babel/register')({
    ignore: [/(node_modules)/],
    presets: [
    [
    '@babel/preset-env',
    {
    targets: {
    node: 'current',
    },
    },
    ],
    ['@babel/preset-react'],
    ],
    })

  • @noherczeg
    @noherczeg 4 года назад +1

    node_modules was misspelled in the ignore section.

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

    good video. Can you have TypeScript version?

  • @lenguajesdeprogramacionson5050
    @lenguajesdeprogramacionson5050 2 года назад

    I’m wondering how to deploy this set app

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

    I got an error React not found when running the app. Could you guys help me please?

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

    If i want to do server side rendering for specific components, is that possible?

  • @reactstack257
    @reactstack257 2 года назад

    Is this indirect solve for SEO problem ?🤨

  • @simongomes5671
    @simongomes5671 2 года назад

    I don't know how it will work for the content pages that we are fetching from APIs

  • @efrainlemus3047
    @efrainlemus3047 2 года назад

    what do you write on minute 9:11? Mine's not working and I don't know if it's because of that

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

    But that not will be useful when you have created a huge mern app

  • @vishalcodepoint2663
    @vishalcodepoint2663 3 года назад

    window is undefined , how to solve this problem? pls tell me if anyone knows

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

    great tutorial but your bottom right corner video layer often covered up the code😥

  • @zeshanjaved6756
    @zeshanjaved6756 2 года назад

    Kindly Make an other video that how can we use react helmet with ssr??

  • @codefantasy
    @codefantasy 4 года назад +1

    Hoy can you tell me how to deploy it? Thanks!

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

    Best video i just glad to know your channel

  • @tedo9425
    @tedo9425 2 года назад +1

    how can i use css with this tutorial?

  • @parisanaderi1647
    @parisanaderi1647 2 года назад

    Does this method work on low version of react as v10 ?

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

    how to render react for differend routes in the same server ?

  • @MrEmgeomap
    @MrEmgeomap 4 года назад +1

    Hi, but this method don't render elements after fetched :(

    • @satansdeer1
      @satansdeer1  4 года назад +1

      Hmm, could you please elaborate, what elements?

    • @MrEmgeomap
      @MrEmgeomap 4 года назад

      @@satansdeer1
      Hello Maxim, i used axios in componentDidMount. I create table body with the data when bring the result, but unfortunately the created elements not rendering after fetching. I'm leaving the github link below
      github.com/Emgeomap/react_ssr

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

    just crazy how much work is required to make this work, i have that you cant just take a already created page and say "this now react SSR" and then it works on your current code

  • @СергейСтрокатов-э4д

    Error: Cannot find module '/mnt/c/PROJECTS/right now/ssr-example/server/index.js'

  • @SangNguyen-gq7wq
    @SangNguyen-gq7wq 3 года назад

    Error: Cannot find module 'app/theme'
    Require stack:
    - D:\F88Projects\WebPartner\src\App.js
    - D:\F88Projects\WebPartner\server\server.js
    - D:\F88Projects\WebPartner\server\index.js
    I get error when run ssr ??
    Please help me!

  • @haskell3702
    @haskell3702 2 года назад

    Do we only need use hydration on root?

  • @yvesgonzaga4223
    @yvesgonzaga4223 4 года назад +1

    Can you give an example with using an API to get the data and render that data server side?

    • @cassette7440
      @cassette7440 4 года назад

      This's not working because i tried (Sorry if my english is bad)

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

    how to deploy this app on cpanel

  • @fahedbrahim39
    @fahedbrahim39 2 года назад

    perfect i love it, but how can i do it with react typescipt template !!! i have some problem

    • @melikekozan7711
      @melikekozan7711 2 года назад

      hi, actually i am finishing writing js but i have some problems. return res.status(500).send("something"). How can I solve it? can you help me?

  • @hovhannesshaxulyan9133
    @hovhannesshaxulyan9133 3 года назад

    yarn ssr, modules not found

  • @tejeshwersinghsachdevtss9627
    @tejeshwersinghsachdevtss9627 3 года назад

    TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type function ([Function (anonymous)])
    at new NodeError (node:internal/errors:329:5)
    at validateString (node:internal/validators:129:11)
    at Object.resolve (node:path:147:9)
    at E:\Web Projects\spacex\server\/server.js:12:22
    at Layer.handle [as handle_request] (E:\Web Projects\spacex
    ode_modules\express\lib
    outer\layer.js:95:5)
    at trim_prefix (E:\Web Projects\spacex
    ode_modules\express\lib
    outer\index.js:317:13)
    at E:\Web Projects\spacex
    ode_modules\express\lib
    outer\index.js:284:7
    at Function.process_params (E:\Web Projects\spacex
    ode_modules\express\lib
    outer\index.js:335:12)
    at next (E:\Web Projects\spacex
    ode_modules\express\lib
    outer\index.js:275:10)
    at expressInit (E:\Web Projects\spacex
    ode_modules\express\lib\middleware\init.js:40:5)
    getting this error

  • @riccardod9690
    @riccardod9690 2 года назад

    what is theme of vscode?

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

    tks for the sharing!

  • @shivammishra4477
    @shivammishra4477 3 года назад

    When m using Routers in my App.js after hitting localhost:8000 it's giving me an error Browser history needs a DOM

  • @kalpittandon8999
    @kalpittandon8999 3 года назад +1

    @Maksim Ivanov How to put this code on production mode on hosting server because we are just putting build folder content on server how server/server.js read App component is this case?

    • @thatcoul
      @thatcoul 3 года назад

      That's what I'm wondering too, did you find the solution?

    • @kalpittandon8999
      @kalpittandon8999 3 года назад +1

      @@thatcoul we have to put all folders on to server. Like we setup on local as same we have to setup on other server like digital ocean node server etc.

    • @thatcoul
      @thatcoul 3 года назад

      @@kalpittandon8999 Thanks

    • @kalpittandon8999
      @kalpittandon8999 3 года назад

      @@thatcoul any time

  • @debjitsinha1
    @debjitsinha1 4 года назад +1

    import logo from './logo.svg'
    the above is not working. Image is not being loaded into the browser. Could you please help me with this?

    • @zathkal4004
      @zathkal4004 3 года назад

      Simply delete both JSX tags mate along with the logo.svg file
      Then it should work (:

  • @MIHANIZM56
    @MIHANIZM56 4 года назад +1

    по сути мы юзаем реакт как эдакий шаблонизатор. В случае с использованием React всё просто. Было бы круто увидеть сср с подключением Redux - там уже не всё так очевидно ))

    • @satansdeer1
      @satansdeer1  4 года назад +1

      Да, можно watering редакс стора рассмотреть

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

    Man You are a Code God.😎. Thanks so so so much. But one more question. Do I need to build my create-react-app anytime I make changes to my Code?

  • @sprintwithcarlos
    @sprintwithcarlos 2 года назад

    2022, the code in the repository doesn't work. The explanation is very good, unfortunately it doesn't work in you clone the repo and run it locally

  • @СергейБерезовский-и6е

    How to deploy this

  • @ahmadkhan-xn2nk
    @ahmadkhan-xn2nk 2 года назад

    sir showing error Warning: Expected server HTML to contain a matching in .

  • @adiemar3974
    @adiemar3974 2 года назад

    man - this is a headache!

  • @ceza121121
    @ceza121121 3 года назад

    Hi thanks for video but i have a issue like:
    ssr: `node server/index.js`
    problem with npm. There is likely additional logging output above.

  • @vansoski
    @vansoski 2 года назад

    nice nice nice nice

  • @nepalcodetv6298
    @nepalcodetv6298 4 года назад

    react-snap is shit doesn't work as needed

  • @vladia391
    @vladia391 2 года назад

    Hey dude, I don't get from where the build thing comes, can you explain? Like there is no build folder in the repo at all

  • @prachigarg7161
    @prachigarg7161 2 года назад

    Will withRouter HOC from React-router-dom work in server side rendering as well?

  • @DeepeshGidwani
    @DeepeshGidwani 2 года назад

    Maksim, how to resolve "ReferenceError: document is not defined" in this implementation ?

  • @estudiantepromedio7722
    @estudiantepromedio7722 3 года назад

    thanks for all

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

    👏

  • @MrJoaopaulofurtado
    @MrJoaopaulofurtado 4 года назад

    If you're reading this comment, do yourself a favor and search for next.js. You're welcome.

  • @oleksiishkulipa1626
    @oleksiishkulipa1626 2 года назад

    thx very much for the tutorial. But what about navigation ? how can i produce SSR with many pages in react ? Thx

  • @trendnowinind
    @trendnowinind 3 года назад

    Hi , The above code works well in the localhost port :8000 but not in production, how do we enable in production mode?

  • @nameholder2402
    @nameholder2402 4 года назад +6

    things are going pretty fast here. I'm not sure whether it's good

    • @talkohavy
      @talkohavy 3 года назад

      Simple answer, it's not.
      Most of it doesn't apply to real world applications, and you can't really learn from it.

  • @devabra_com
    @devabra_com 3 года назад

    very good solution. is it works redux case?

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

    God bless You !
    If You would be so kind as to post some extended material using routing, that would be nice

  • @elite.topmotivation
    @elite.topmotivation 8 месяцев назад

    I got this to work on the all new "bun.js" runtime, no need for babel but I had to do some modifications. Good Tutorial, thanks

  • @iliasvinin8718
    @iliasvinin8718 3 года назад

    Maksim you are Molotok! How do we deploy it? Usually I upload build content to server, but what should I do after your tutorial?

  • @LonelyRiderStonerBand
    @LonelyRiderStonerBand 2 года назад

    did everything like in a video, "Reference Error: React is not defined", might versions are not matched or something missed ;)

  • @48_subhambanerjee22
    @48_subhambanerjee22 Год назад

    Nice

  • @corndoggydogdog
    @corndoggydogdog 2 года назад

    Hi there, does this solution generate html on the serverside? It's not quite clear from the video if it does. Last question can it generate html for a specific component within the react app?

  • @yt-sh
    @yt-sh 2 месяца назад

    This helped understand SSR better, thank you

  • @pokegaiyui
    @pokegaiyui 3 года назад

    Can you talk about why would someone go fully this route vs nextjs or gatsby?

  • @sanyokes
    @sanyokes 4 года назад +4

    Просто великолепно, начал сейчас учить реакт в связке MERN и мне очень важен SSR для СЕО, а тут все так понятно, спасибо за качественный контент)

    • @МаксВолков-э6и
      @МаксВолков-э6и 2 года назад

      А этот метод Вам помог? Для меня тоже очень важен ceo, а писать приложения на next js не особо хочется

    • @sanyokes
      @sanyokes 2 года назад

      @@МаксВолков-э6и Добрый вечер! Этот метод в итоге не пробовал, решил использовать Next.js, всё таки это более распространенное решение, много примеров как и что правильно делать

    • @МаксВолков-э6и
      @МаксВолков-э6и 2 года назад

      @@sanyokes Спасибо за ответ!

  • @CoderDmitri
    @CoderDmitri 3 года назад

    I think I just learned THE DIM MAK on this page... thank you so much, you are LORD!

  • @Cdswjp
    @Cdswjp 2 года назад

    Great. Thanks. What does ^/$ mean exactly?

  • @huynhdan8092
    @huynhdan8092 4 года назад +1

    Can redux and routing be used?

  • @raorobin0
    @raorobin0 4 года назад

    Support for the experimental syntax 'classProperties' isn't currently enabled , getting this error