by Adam Recvlohe
import React, { Component } from "react";
import { render } from "react-dom";
function withHandlers(WrappedComponent) {
return class extends Component {
state = {
name: ""
};
handleChange = e => {
this.setState({ [e.target.name]: e.target.value });
};
render() {
const { handleChange } = this;
const { name } = this.state;
const props = {
name,
handleChange
};
return <WrappedComponent {...this.props} {...props} />;
}
};
}
function Form({ handleChange, name }) {
return <input value={name} name="name" onChange={handleChange} />;
}
const App = withHandlers(Form);
render(<App />, document.getElementById("root"));
import React, { Component } from "react";
import { render } from "react-dom";
class RenderMouseMoves extends Component {
state = {
x: 0,
y: 0
};
handleMouseMove = e => {
this.setState({ x: e.clientX, y: e.clientY });
};
render() {
return (
<div onMouseMove={this.handleMouseMove} style={{ height: "100vh" }}>
{this.props.render(this.state)}
</div>
);
}
}
render(
<RenderMouseMoves
render={({ x, y }) => {
return (
<div>
{x} and {y}
</div>
);
}}
/>,
document.getElementById("root")
);
Pattern !== Architecture