Git Product home page Git Product logo

react-meteor-components-demo's Introduction

git clone https://github.com/crapthings/react-meteor-components-demo --recursive
cd react-meteor-components-demo
meteor npm i
meteor

USAGE

import React, { Component } from 'react'
import { render } from 'react-dom'
import lfc from 'lodash-form-collector'

import {
  WithSubscribe,
  WithTracker,
  WithCall,
  WithUserId,
  WithoutUserId,
} from 'meteor/crapthings:react-meteor-components'

const Demo1 = () => {
  return (
    <div>
      <h3>subscribe to an reactive list</h3>
      <WithSubscribe name='users'>
        <WithTracker list={context => Users.find()}>
          {({ data: { list: users } }) => (
            users.map(({ _id, name }) => (
              <div key={_id}>{name}</div>
            ))
          )}
        </WithTracker>
      </WithSubscribe>
    </div>
  )
}

const Demo2 = () => {
  return (
    <div>
      <h3>subscribe to an reactive item</h3>
      <WithSubscribe name='user'>
        <WithTracker item={context => Users.findOne({ name: { $exists: true } })}>
          {({ data: { item: { _id, name} } }) => (
            <div>{name}</div>
          )}
        </WithTracker>
      </WithSubscribe>
    </div>
  )
}

const Demo3 = () => {
  return (
    <div>
      <h3>tracker with data props</h3>
      <WithSubscribe name='users'>
        <WithTracker data={{
          title: 'this is a title',
          users: context => Users.find(),
        }}>
          {({ data: { title, users } }) => (
            <div>
              <h4>{title}</h4>
              {users.map(({ _id, name }) => (
                <div key={_id}>{name}</div>
              ))}
            </div>
          )}
        </WithTracker>
      </WithSubscribe>
    </div>
  )
}

const Demo4 = () => {
  return (
    <div>
      <h3>meteor call</h3>
      <WithCall name='users'>
        {({ data: users }) => {
          return users.map(({ _id, name }) => (
            <div key={_id}>{name}</div>
          ))
        }}
      </WithCall>
    </div>
  )
}

const Demo5 = () => {
  return (
    <div>
      <h3>with user id</h3>
      <WithUserId>
        <button onClick={() => Meteor.logout()}>logout</button>
      </WithUserId>
    </div>
  )
}


const Demo6 = () => {
  return (
    <div>
      <h3>without user id</h3>
      <WithoutUserId>
        <form onSubmit={evt => {
          evt.preventDefault()
          const { username, password } = lfc(evt.target)
          Meteor.loginWithPassword(username, password)
        }}>
          <div>
            <input type='input' name='username' defaultValue='demo' />
          </div>
          <div>
            <input type='password' name='password' defaultValue='demo' />
          </div>
          <div>
            <input type='submit' />
          </div>
        </form>
      </WithoutUserId>
    </div>
  )
}

const Example = () => <div id='example-wrapper'>
  <Demo1 />
  <Demo2 />
  <Demo3 />
  <Demo4 />
  <Demo5 />
  <Demo6 />
</div>

Meteor.startup(function () {
  const app = document.createElement('div')
  app.id = 'app-wrapper'
  document.body.appendChild(app)
  render(<Example />, app)
})

react-meteor-components-demo's People

Contributors

crapthings avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.