Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support koa2? #22

Open
hskww opened this issue Jul 14, 2016 · 2 comments
Open

support koa2? #22

hskww opened this issue Jul 14, 2016 · 2 comments

Comments

@hskww
Copy link

hskww commented Jul 14, 2016

No description provided.

@icflorescu
Copy link

Apparently it does support koa@2.

I've just tested a very simple workflow with koa-react-view@3.0.0, koa@2.0.0-alpha.7:

// bootstrap.js:

require('babel-core/register')({ presets: ['latest-minimal', 'react'] });
require('./app');

Start server:

// app.js:

import Koa             from 'koa';
import setupViewEngine from 'koa-react-view';

const app = new Koa();

setupViewEngine(app, {
  views: `${__dirname}/views`,
  extname: 'js'
});

app.use(async ctx => {
  ctx.state = {
    title: 'Awesome app',
    viewEngine: 'React'
  };
  await ctx.render('home');
});

app.listen(3000);

This works as expected and it renders both ES6 classes:

// views/home.js:

import React, { Component } from 'react';

export default class Home extends Component {
  render() {
    return (
      <html>
        <head>
          <title>{this.props.title}</title>
        </head>
        <body>
          <h1>{this.props.title}</h1>
          <p className="test">Page rendered with {this.props.viewEngine} view engine.</p>
        </body>
      </html>
    );
  }
};

...and stateless functional components:

// views/home.js:

import React from 'react';

export default props => (
  <html>
    <head>
      <title>{props.title}</title>
    </head>
    <body>
      <h1>{props.title}</h1>
      <p className="test">Page rendered with {props.viewEngine} view engine.</p>
    </body>
  </html>
);

I'm just curious, did you encounter a specific use-case where this engine didn't work with koa@2?

@afenton90
Copy link

I have also managed to get this working with koa@2 and koa-react-view@3.0.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants