【发布时间】:2016-12-29 08:10:42
【问题描述】:
我有一些功能需要在几个组件中使用,所以我将它们放在这样的模块中。
export default class FormFunctions {
handleChange (event) {
const changedOne = event.target.name
const newValue = event.target.value
const newState = {}
newState[changedOne] = newValue
this.setState(newState)
}
handleSubmit (infoToPass, toThisMethod) {
Meteor.call(toThisMethod, infoToPass, function () {
console.log('userCreate call callback')
})
}
}
如何将它们用作组件的方法?
我试过这样但它不起作用。而且我不确定我是否需要任何课程。
import React, { Component } from 'react'
import Register from './Register.jsx'
import FormFunctions from './FormFunctions'
class RegisterLogic extends Component {
render () {
return <Register
handleChange={this.handleChange}
handleSubmit={this.handleSubmit}
/>
}
}
export default RegisterLogic
【问题讨论】:
标签: javascript reactjs ecmascript-6 es6-modules