All Projects → insin → React Router Form

insin / React Router Form

Licence: mit
<Form> is to <form> as <Link> is to <a>

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to React Router Form

Isomorphic Lab
Isomorphic React experimentation
Stars: ✭ 144 (+148.28%)
Mutual labels:  experiment, forms, react-router
React Router Active Component
Factory function for React components which are active for a particular React Router route
Stars: ✭ 116 (+100%)
Mutual labels:  react-component, react-router
React Auto Form
Simplifies getting user input from forms via onChange and onSubmit events, using DOM forms APIs
Stars: ✭ 116 (+100%)
Mutual labels:  react-component, forms
awesome-web-react
🚀 Awesome Web Based React 🚀 Develop online with React!
Stars: ✭ 31 (-46.55%)
Mutual labels:  react-router, react-component
React Router Ga
Google Analytics component for React Router
Stars: ✭ 66 (+13.79%)
Mutual labels:  react-component, react-router
git-issue-react-electronjs
⚙️. ⚛️. A desktop application created with Electronjs and Reactjs to be cross-platform to manage and track GitHub issues.
Stars: ✭ 21 (-63.79%)
Mutual labels:  react-router, react-component
React Sight
Visualization tool for React, with support for Fiber, Router (v4), and Redux
Stars: ✭ 2,716 (+4582.76%)
Mutual labels:  react-component, react-router
whatsapp-clone-react
Build a WhatsApp Clone with React JS and FireBase.
Stars: ✭ 38 (-34.48%)
Mutual labels:  react-router, react-component
Registration-and-Login-using-MERN-stack
Simple Registration and Login component with MERN stack
Stars: ✭ 210 (+262.07%)
Mutual labels:  react-router, react-component
insect
🛠 Highly customisable, minimalistic input x select field for React.
Stars: ✭ 33 (-43.1%)
Mutual labels:  forms, react-component
React Router Util
Useful components and utilities for working with React Router
Stars: ✭ 320 (+451.72%)
Mutual labels:  react-component, react-router
react-pits
React 中的坑
Stars: ✭ 29 (-50%)
Mutual labels:  react-router, react-component
React Router Server
Server Side Rendering library for React Router v4.
Stars: ✭ 443 (+663.79%)
Mutual labels:  react-component, react-router
Tensorflow Lstm Sin
TensorFlow 1.3 experiment with LSTM (and GRU) RNNs for sine prediction
Stars: ✭ 52 (-10.34%)
Mutual labels:  experiment
Egg React Typescript Boilerplate
Egg React TypeScript Server Side Render (SSR) / Client Side Render (CSR)
Stars: ✭ 56 (-3.45%)
Mutual labels:  react-router
Formio.js
JavaScript powered Forms with JSON Form Builder
Stars: ✭ 1,060 (+1727.59%)
Mutual labels:  forms
React Contenteditable
React component for a div with editable contents
Stars: ✭ 1,057 (+1722.41%)
Mutual labels:  react-component
Simple Universal React Redux
The simplest possible Async Universal React & Redux Boilerplate app, that works on both Mac and Windows
Stars: ✭ 58 (+0%)
Mutual labels:  react-router
React Cool Starter
😎 🐣 A starter boilerplate for a universal web app with the best development experience and a focus on performance and best practices.
Stars: ✭ 1,083 (+1767.24%)
Mutual labels:  react-router
React 5ddm
5d动漫,使用React,服务端渲染,接口(不开源)来自赞片CMS。仅供参考,交流群:14646823 欢迎加入
Stars: ✭ 50 (-13.79%)
Mutual labels:  react-router

React Router <Form>

Travis npm package Coveralls

A <Form> component for use with React Router which does for <form> what react-router's <Link> does for <a>.

Usage

A <Form> component renders a <form> element with the contents you provide, hooks into the form's onSubmit event to extract user input and transitions to the configured route with user input data in the next location's state.

import React from 'react'
import Form from 'react-router-form'

let NewPost = React.createClass({
  render() {
    <Form to={`/topics/${this.props.params.topicId}/add-post`} method="POST">
      <textarea name="comment"/>
      <button type="submit">Add Post</button>
    </Form>
  }
})

For example, assuming you have the following routes, the component above would trigger the onEnter handler for the add-post route when the form is submitted:

<Route path="/topics/:topicId/new-post" component={NewPost}/>
<Route path="/topics/:topicId/add-post" onEnter={handleAddPost}/>

Form data is set as a body property and the form's method is set as a method property in the next location's state:

function handleAddPost(nextState, replaceState) {
  console.log(nextState.location.state.method) // 'POST'
  console.log(nextState.location.state.body) // {comment: '...'}
}

Goals

One of the key goals of this component is to make it easier to implement basic isomorphic forms in your React app.

If your onEnter handlers send back everything needed to re-render a form which has errors (i.e. validation errors and user input), then for a little extra effort your React components can handle form submissions on both client and server:

function handleAddPost(nextState, replace, callback) {
  let comment = nextState.location.state.body
  let {topicId} = nextState.params
  ForumService.addComment({comment, topicId})
    .then(({page}) => {
      replace(`/topics/${topicId}?page=${page}`)
    })
    .catch(errors => {
      replace({
        pathname: `/topics/${topicId}/new-post`,
        state: {comment, errors}.
      })
    })
    .finally(callback)
}

Install

# For React Router 3.x
npm install react-router-form

# For React Router 1.x
npm install [email protected]
import Form from 'react-router-form'
// or
const Form = require('react-router-form')

Browser bundles are available, which export a global ReactRouterForm variable and expect to find a global React variable to work with.

MIT Licensed

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].