Created
April 18, 2020 16:28
-
-
Save suhas86/b29801f0a73a4913172fc8c7ec0a8fba to your computer and use it in GitHub Desktop.
This file contains hidden or 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, { Component, createContext } from 'react' | |
type teamState = { | |
team:string | |
} | |
export const TeamContext = createContext<{team:string,changeTeam:any}>({team:"rcb",changeTeam:null}) | |
class TeamProvider extends Component<{},teamState> { | |
constructor(props:{}){ | |
super(props); | |
this.changeTeam = this.changeTeam.bind(this) | |
} | |
state: teamState = { | |
team:"rcb" | |
} | |
changeTeam(e:React.ChangeEvent<HTMLInputElement>) { | |
this.setState({team:e.target.value}) | |
} | |
render() { | |
return ( | |
<TeamContext.Provider value={{...this.state,changeTeam:this.changeTeam}}> | |
{this.props.children} | |
</TeamContext.Provider> | |
) | |
} | |
} | |
export default TeamProvider; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment