我有一些功能,我需要讓我把他們像這樣的一個模塊中的若干組件使用。陣營之外使用功能的方法
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'。這就是爲什麼他們是靜態的。 –
我試過這個,它實際上工作! –