Shai Kimchi
Shai Kimchi

Reputation: 786

ReactJS pass component as var (in ecma6)

in one js file I have a component :

import React from 'react';
export default class ImageGrid extends React.Component {
  render(){
    return <div>ImageGrid1</div>
  }
}

I want to render the above component from another component using a 'var', and I cant figure out the syntax:

import React from 'react';
import ImageGrid from 'components/imageGrid';
class HomePage extends React.Component {
  render() {
    var div1=ImageGrid;
    return (div1); // what is the proper syntax?
  }
}

Upvotes: 1

Views: 49

Answers (1)

ffxsam
ffxsam

Reputation: 27783

This is what you want.

import React from 'react';
import ImageGrid from 'components/imageGrid';

class HomePage extends React.Component {
  render() {
    var SomeComponent = ImageGrid;

    return <SomeComponent />
  }
}

Upvotes: 2

Related Questions