This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// HOC using Class Component | |
function Wrap(WrappedComponent) { | |
return class extends React.Component { | |
render() { | |
// Copy the props so we don't mutate the original component | |
const newProps = {...this.props}; | |
// Loop through the props and check if the props ia a number | |
for (let [key, value] of Object.entries(newProps)) { | |
if (typeof value === "number") { | |
// Increase the prop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { Provider1, Provider2, Provider3 } from './'; | |
function ProviderComposer({ contexts, children }) { | |
return contexts.reduceRight( | |
// kids = accumulator, parent = currentValue | |
(kids, parent) => | |
React.cloneElement(parent, { | |
children: kids | |
}), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Actual Code | |
constructor() { | |
super(); | |
this.state = { | |
name: "", | |
email: "", | |
password: "", | |
password2: "", | |
errors: {} | |
}; |