Clean code and pretty
This commit is contained in:
parent
ebe310266c
commit
78cfd6db95
@ -1,6 +1,6 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
|
|
||||||
const BaseContext = React.createContext({ base: 'Context' })
|
const BaseContext = React.createContext({base: 'Context'})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Component : BaseContextProvider
|
* Component : BaseContextProvider
|
||||||
@ -23,30 +23,30 @@ class BaseContextProvider extends React.Component {
|
|||||||
render() {
|
render() {
|
||||||
const contextReturn = this.getContextReturnValue()
|
const contextReturn = this.getContextReturnValue()
|
||||||
const Context = this.getContext()
|
const Context = this.getContext()
|
||||||
const { children } = this.props
|
const {children} = this.props
|
||||||
|
|
||||||
return <Context.Provider value={contextReturn}>{children}</Context.Provider>
|
return <Context.Provider value={contextReturn}>{children}</Context.Provider>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const baseContextWrap = (Provider) => {
|
export const baseContextWrap = (Provider) => {
|
||||||
return (Component) => (props) => <Provider children={<Component {...props} />} />
|
return (Component) => (props) => <Provider children={<Component {...props} />}/>
|
||||||
}
|
}
|
||||||
|
|
||||||
export function baseUseContext(context) {
|
export function baseUseContext(context) {
|
||||||
return function() {
|
return function () {
|
||||||
return React.useContext(context)
|
return React.useContext(context)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function baseWithContext(context, contextPassPropKey) {
|
export function baseWithContext(context, contextPassPropKey) {
|
||||||
const Consumer = context.Consumer
|
const Consumer = context.Consumer
|
||||||
return (Component) => (props) => (
|
return (Component) => (props) => (
|
||||||
<Consumer>
|
<Consumer>
|
||||||
{(contextValue) => (
|
{(contextValue) => (
|
||||||
<Component {...{ ...props, [contextPassPropKey]: contextValue }} />
|
<Component {...{...props, [contextPassPropKey]: contextValue}} />
|
||||||
)}
|
)}
|
||||||
</Consumer>
|
</Consumer>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user