Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

avocode/reactmemory

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ReactMemory

React renderer which works without DOM and does not render anything anywhere

Motivation

Since React components encapsulate logic nicely and compose seamlessly, it starts being a pain to write headless (DOM-less) runtimes without it. This renderer allows writing general application logic (Node.js apps, Electron main process) as React components with JSX used for composition.

Example

function App({ process }) {
  useEffect(() => {
    console.log('App started')
    return () => {
      console.log('App terminated')
    }
  }, [])

  return (
    <>
      <Server port={process.env['PORT']} />
    </>
  )
}

function Server({ port }) {
  useEffect(() => {
    const server = http.createServer()
    server.listen(port)
    console.log(`Server starting on port ${port}`)

    return () => {
      server.close()
      console.log('Server stopped')
    }
  }, [port])

  return null
}

ReactMemory.render(
  <App />,
  ReactMemory.createRoot()
)

What Is Supported

  • class and functional components
  • fragments
  • hooks
  • mounting (the full lifecycle)
  • rerendering of the root
  • multiple root nodes

What Is NOT Supported

Please report anything you encounter.

License

MIT

About

ReactMemory.render(<App />, ReactMemory.createRoot())

Resources

Stars

2 stars

Watchers

2 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Morty Proxy This is a proxified and sanitized view of the page, visit original site.