react-add-more

1.0.8 • Public • Published

react-add-more

add more fields group into form

NPM JavaScript Style Guide

Install

npm install --save react-add-more

Usage

import React, { Component, useState } from 'react'
import Addmore from 'react-add-more'

const Item = ({ value, onChange }) => {
  const [obj, setObj] = useState(value)
  const handleChange = (key, value) => {
    const newObj = { ...obj, [key]: value }
    setObj(newObj)
    onChange(newObj)
  }
  return (
    <div>
      <span>A:</span>
      <input onChange={e => handleChange('a', e.target.value)} value={obj.a} />
      <span>B:</span>
      <input onChange={e => handleChange('b', e.target.value)} value={obj.b} />
    </div>
  )
}
export default class App extends Component {
  state = {
    value: [{ a: 1, b: 2 }],
  }
  render() {
    return (
      <div style={{ width: '400px' }}>
        <Addmore
          value={this.state.value}
          Item={Item}
          onChange={value => {
            this.setState({ value: [] })
            console.log('result', value)
          }}
        />
      </div>
    )
  }
}

License

MIT © jack

Readme

Keywords

none

Package Sidebar

Install

npm i react-add-more

Weekly Downloads

1

Version

1.0.8

License

MIT

Unpacked Size

28.1 kB

Total Files

7

Last publish

Collaborators

  • jackjiang