• Stars
    star
    130
  • Rank 277,575 (Top 6 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 9 years ago
  • Updated almost 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A simple way to mount React components

React Mounter

React Mounter lets you mount React components to DOM easily.

React Mounter supports Server Side Rendering when used with FlowRouter.

Normally, when you are rendering a React Component to the DOM, you need to do following things basically,

  • Create a root DOM node as the root node for React
  • Wait for the DOM to load properly
  • Then render the component

React Mounter does all these for you. You just ask it to render a component.

Additionally, React Mounter can work as a simple Layout Manager where you can use with Flow Router.

Basic Usage

Install with:

npm i --save react-mounter react react-dom

react and react-dom are peerDependencies of react-mounter. So, you need to install them into your app manually.

Then let's mount a component.

import React from 'react';
import {mount} from 'react-mounter';

const WelcomeComponent = ({name}) => (<p>Hello, {name}</p>);

mount(WelcomeComponent, {name: 'Arunoda'});

Using as a Layout Manager

You can user react-mounter as a layout Manager for Flow Router. Here's how to do it.

Let's say we've a layout called MainLayout.

const MainLayout = ({content}) => (
    <div>
      <header>
        This is our header
      </header>
      <main>
        {content}
      </main>
    </div>
);

Now let's try render to our WelcomeComponent into the MainLayout.

mount(MainLayout, {
  content: <WelcomeComponent name="Arunoda" />
});

That's it.

To use the React Context

In order to use the React context, you need to render the content component inside the layout. So we need to pass a function instead of the React element. Here's how to do it.

const MainLayout = ({content}) => (
    <div>
      <header>
        This is our header
      </header>
      <main>
        {content()}
      </main>
    </div>
);

See, now content is a function.

Then, we can pass the Welcome component like this:

mount(MainLayout, {
  content: () => (<WelcomeComponent name="Arunoda" />)
});

Configure Root DOM node

By default React Mounter render our components into a DOM node called react-root. But, you can configure if by like below:

const {mount, withOptions} from `react-mounter`;
const mount2 = withOptions({
    rootId: 'the-root',
    rootProps: {'className': 'some-class-name'}
}, mount);

mount2(WelcomeComponent, {name: 'Arunoda'});

Server Side Rendering (SSR)

SSR is supported when used with FlowRouter SSR. Checkout this sample app.

More Repositories

1

lokka

Simple JavaScript Client for GraphQL
JavaScript
1,532
star
2

flow-router

Carefully Designed Client Side Router for Meteor
JavaScript
1,089
star
3

mantra

Mantra - An Application Architecture for Meteor
Shell
980
star
4

fast-render

Render you app even before the DDP connection is live. - magic?
JavaScript
559
star
5

subs-manager

Subscriptions Manager for Meteor
JavaScript
358
star
6

graphql-errors

Better error handling for GraphQL
JavaScript
253
star
7

blaze-layout

Layout Manager for Blaze (works well with Meteor FlowRouter)
JavaScript
198
star
8

npm-base

A base package for creating NPM packages with ES2015
JavaScript
161
star
9

meteor-debug

Full Stack Debugging Solution for Meteor
JavaScript
152
star
10

meteor-react-layout

Simple React Layout Manager for Meteor with SSR Support
JavaScript
138
star
11

meteor-dochead

Isomorphic way to manipulate document.head for Meteor apps
JavaScript
134
star
12

meteor-graphql

GraphQL Support for Meteor with Lokka
JavaScript
90
star
13

graphql-blog-schema

GraphQL Schema for a Blog App
CSS
84
star
14

graphqlify

Build GraphQL queries with JavaScript
JavaScript
56
star
15

react-simple-di

Simple Dependancy Injection Solution for React
JavaScript
56
star
16

react-stubber

Simple but useful stubbing solution React
JavaScript
50
star
17

blaze-plus

Adds Props and State Management functionality to Meteor's Blaze Template Engine.
JavaScript
50
star
18

meteor-login-state

Share Login State Between the Domain
JavaScript
45
star
19

meteor-reaktor

Easy to use React Frontend for FlowRouter
JavaScript
42
star
20

lokka-transport-http

HTTP Transport Layer for Lokka
JavaScript
41
star
21

lokka-transport-jwt-auth

Lokka GraphQL Transport with JWT Support
JavaScript
22
star
22

graphql-utils-js

A set of utilities for apps building with graphql-js
JavaScript
20
star
23

mongo-sharded-cluster

Shard MongoDB in the app layer
JavaScript
13
star
24

meteor-stripe-konnect

Stripe for Meteor Apps
JavaScript
12
star
25

mantra-tutor-lessons

11
star
26

kadiyadb

KadiraDB is a low level database for storing time series data
Go
10
star
27

node-eventloop-monitor

Simple way to monitor eventloop blockness in Node.js
JavaScript
9
star
28

node-base

Base app for all the server side node apps at Kadira
JavaScript
6
star
29

nofat

Set of tools to kick start server side ES2016 development
JavaScript
6
star
30

kadira-core

JavaScript
5
star
31

regex-query-filter

JavaScript
3
star
32

storybook-addon-hello

A simple hello-world example addon for storybook
JavaScript
3
star
33

lokka-transport-http-auth

HTTP Transport for Lokka with Basic Auth
JavaScript
2
star
34

meteor-string-highlighter

String Highlighter for Meteor Apps
JavaScript
2
star
35

fastcall

A fast bi-directional communication layer over tcp
Go
2
star
36

storybook-ping-receiver

Listen to anonymous usage pings sent from storybooks
JavaScript
2
star
37

url-mailer

JavaScript
2
star
38

kadira-debug-toy

MeteorToys integration for kadira:debug Package
JavaScript
2
star
39

kadira.io

Kadira Blog
JavaScript
2
star
40

go-tools

Go tools is a collection of re-usable go packages used by multiple KadiraHQ projects
Go
2
star
41

mongo-mask

Replaces data with masked values in mongo queries
JavaScript
1
star
42

kadiradb-node

NodejS client for KadiraDB metrics database.
JavaScript
1
star
43

kadiradb

A real time metrics database which uses KadiraDB under the hood
Go
1
star