我有一些功能,我需要让我把他们像这样的一个模块中的若干组件使用。阵营之外使用功能的方法
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
1.不能工作,因为你不能在静态中访问'this'。这就是为什么他们是静态的。 –
我试过这个,它实际上工作! –