Coder Social home page Coder Social logo

Comments (1)

marshalhayes avatar marshalhayes commented on April 29, 2024

I haven't used the React Dev Tools extension you're asking about, but I want to clarify something.

This system is completely server-side. There is no JavaScript rendered to the client at all. We import React tools, yes, but again that's on the server-side. From the client's perspective there is no way to know we are using React. If you setup a simple express server with a controller, say:

const ReactDOMServer = require('react-dom/server');

// An express controller
app.get('/', function (req, res) {
  // Assume this loads the React view
  const loadedComponent = ...;

  res.status(200);
  res.send(ReactDOMServer.renderToStaticMarkup(loadedComponent));
});

The key here is renderToStaticMarkup(). You can read the docs, but it only generates HTML markup. No React anything.

Now, with that said, I don't think it would then be possible for the React Dev Tools extension to know the markup came from React.

However, you could follow what the React docs recommend if you want your server-rendered React components to become interactive and:

...use renderToString on the server and ReactDOM.hydrate() on the client

This would theoretically indicate to the React Dev Tools extension that you're using React since:

  1. The HTML generated by the server includes React attributes
  2. You include the react-dom library as a script tag
  3. You call ReactDOM.hydrate(), even further using client-side React things

I'm personally not using React in that way, but I'm sure you could get it to work.

from express-react-views.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.