Skip to content
This repository has been archived by the owner on Feb 1, 2022. It is now read-only.

React component use #148

Open
hyphen1370 opened this issue Oct 30, 2019 · 1 comment
Open

React component use #148

hyphen1370 opened this issue Oct 30, 2019 · 1 comment

Comments

@hyphen1370
Copy link

Hello,

Is that possible to run react components with express-react-views? I have the following code in index.jsx:

/* eslint-disable indent */
/* eslint-disable react/destructuring-assignment */
/* eslint-disable react/prop-types */
/* eslint-disable react/jsx-one-expression-per-line */
/* eslint-disable react/jsx-fragments */
/* eslint-disable react/jsx-indent */
/* eslint-disable react/prefer-stateless-function */
import React from 'react';

class Index extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            title: ''
        };
    }

    componentDidMount() {
        this.setState({
            title: this.props.title
        });
    }

    testState = {
        title: 'Test'
    };

    render() {
        return (
            <React.Fragment>
                <div>This is a test {this.state.title}</div>
                <div>This is a test {this.props.title}</div>
                <div>This is a test {testState.title}</div>
            </React.Fragment>
        );
    }
}

export default Index;

It doesn't pass the value to this.state.title in componentDidMount(). Also, it gives me error about

testState = {
        title: 'Test'
    };

The error is Parsing error: Unexpected token =eslint. This syntax works in native react app.

The index router has the following code:


const { Router } = require('express');

const router = Router();

/* GET index page. */
router.get('/', (req, res) => {
  res.render('index', {
    title: 'Express'
  });
});

module.exports = router;

Thanks

@zpao
Copy link
Member

zpao commented Nov 22, 2019

Not sure what the problem is here. Your error mentions eslint, which is odd. But you may need to override the babel config if you're using module syntax.

In all honesty, I'd recommend something like next.js these days.

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

No branches or pull requests

2 participants