Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple React component not rendering

I have created a simple React component which displays another react component. But it doesn't render in browser :

class Home extends React.Component {   render() {     return (       <div>         <map/>       </div>        );   } }  var map = React.createClass({    render: function() {       return (           <div id="map-canvas">             <span>hello</span>           </div>       );     } }); 

I'm expecting the hello to show up on the screen, but nothing shows up and when I inspect the element all I can see is

<map data-reactid=".0.0"></map> 

Can any one point our what might be wrong.

like image 307
iJade Avatar asked Apr 24 '15 14:04

iJade


People also ask

How do you force component to render in React?

Forcing an update on a React class component In any user or system event, you can call the method this. forceUpdate() , which will cause render() to be called on the component, skipping shouldComponentUpdate() , and thus, forcing React to re-evaluate the Virtual DOM and DOM state.

Can you React component without rendering?

Nope, render() method can't return an empty array or anything other than other React component.

Do React components need render?

Rendering is an essential procedure a programmer has to manage in frontend development. In React, the render() method is the only required method in a class component and is responsible for describing the view to be rendered to the browser window.

What is the name of components that don't render any other component?

Presentational Components These have also been referred to in the past as "dumb components". These components have no (or at least very little) logic, and do not use any lifecycle methods other than render() .


1 Answers

JSX expects component tags to be capitalized. Otherwise, it will just create a DOM element with the provided tag. See HTML Tags vs. React Components.

<map /> compiles to React.createElement("map", {}); while <Map /> compiles to React.createElement(Map, {});.

Just rename map to Map and you're good.

like image 90
Alexandre Kirszenberg Avatar answered Sep 26 '22 01:09

Alexandre Kirszenberg