folkloreinc / laravel-hypernova

Laravel package to use Hypernova server-side rendering service of Javascript UI Components (React)
https://github.com/airbnb/hypernova
14 stars 7 forks source link

example? #1

Open koenverburg opened 7 years ago

koenverburg commented 7 years ago

Can you make an example. The Hypernova-ruby uses this in there templating engine.

<%=
  render_react_component(
    'MyComponent.js',
    :name => 'Person',
    :color => 'Blue',
    :shape => 'Triangle'
  )
%>

Can we write something like this to render a component which is wrapped with hypernova-react?


{{
  render_react_component( 'MyComponent.js', [
    'name' => 'Person', 'props' => 'value' 
  ])
}}
koenverburg commented 7 years ago

Can you give an update on this?

dmongeau commented 7 years ago

Yes there is a blade directive called hypernova that you can use like in your example:

@hypernova( 'MyComponent.js', [
    'name' => 'Person', 'props' => 'value' 
])
eightyfive commented 7 years ago

Directive only works when Middleware is activated:

// app/Http/Kernel.php
protected $middleware = [
    ...
    \Folklore\Hypernova\HypernovaMiddleware::class,
];

@dmongeau correct me if I'm wrong: Directive only outputs placeholders. They are replaced in Middleware by corresponding Hypernova job result (HTML string).

Please note that there seems to be a bug in the Middleware.

Finally, the following blog post helped me to get started: https://blog.larah.me/2017/04/10/react-server-side-rendering/

dmongeau commented 7 years ago

Yes you are right, you need the middleware, because by outputting only a placeholder, if the rendering server doesn't work, the client code render the UI instead. But I really have a job to make this package "more public" with doc didn't expect, it will be used in this state. But I'm open to any PR improving it

aftabnaveed commented 6 years ago

@dmongeau Does each call to @hypernova directive addJob to the batch? And all components are then sent to the server at once?

aftabnaveed commented 6 years ago

I can answer my question now and yes it does!