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

React component use #148

Description

@hyphen1370

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions