Skip to content

Instantly share code, notes, and snippets.

@anmolsukki
Last active May 5, 2020 06:40
Show Gist options
  • Select an option

  • Save anmolsukki/e6682426b9c8dd954c82deb04ea73abf to your computer and use it in GitHub Desktop.

Select an option

Save anmolsukki/e6682426b9c8dd954c82deb04ea73abf to your computer and use it in GitHub Desktop.
import React from "react";
import Rahul from "./Components/Rahul";
import Rose from "./Components/Rose";
function App() {
return (
<div className="App">
<Rahul camp="120" />
<Rose camp="140" />
</div>
);
}
export default App;
// Component/Rahul.js
import React, { Component } from "react";
import WithArms from "../Hoc/WithArms";
class Rahul extends Component {
render() {
return (
<div>
<h2>camp: {this.props.camp}</h2>
<h3 onMouseOver={this.props.hocHandleGunShots}>
Rahul {this.props.hocGunName} GunShots: {this.props.hocGunShots}
</h3>
</div>
);
}
}
export default WithArms(Rahul, 10);
// Component/Rose.js
import React, { Component } from "react";
import WithArms from "../Hoc/WithArms";
class Rose extends Component {
render() {
return (
<div>
<h2>camp: {this.props.camp}</h2>
<h3 onMouseOver={this.props.hocHandleGunShots}>
Rahul {this.props.hocGunName} GunShots: {this.props.hocGunShots}
</h3>
</div>
);
}
}
export default WithArms(Rose, 20);
// Hoc/WithArms.js
import React, { Component } from "react";
const WithArms = (Men, shot) => {
class newArms extends Component {
constructor() {
super();
this.state = {
gunShots: 0
};
}
handleShots = () => {
this.setState({
gunShots: this.state.gunShots + shot
});
};
render() {
return (
<div>
<Men
hocGunName="Ak47"
hocGunShots={this.state.gunShots}
hocHandleGunShots={this.handleShots}
{...this.props}
/>
</div>
);
}
}
return newArms;
};
export default WithArms;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment