This can be a pretty general question on how to handle importing external functions and exporting functions.
So I have component
:
import React, {Component} from "react";
import {handleChange} from "./path";
class Foo extends Component {
constructor(props) {
super(props);
this.bindFunctions();
this.state = {...};
};
alreadyBound = () => {};
render() {
return (
<div>
Some text
</div>
);
}
bindFunctions = () => {
this.handleChange = handleChange.bind(this);
}
}
export default compose(
translate('translations'),
connect()
)(Foo);
Here's what my external functions look like (they are not part component
, just files with functions that will be reused in various components
):
export function handleChange(value, {target: {name, type}}) {
this.setState({[name]: value});
}
Now it works fine, but it is sickening. My files grow in size, and it’s always a pain of bind
these functions. I get the need to import functions / components, but do I really need bind
them that way? Something like functions arrow
would be neat and save me from typing too much. Thanks in advance!
source
share