init lib
This commit is contained in:
@@ -17,8 +17,8 @@
|
||||
"@types/node": "link:../node_modules/@types/node",
|
||||
"@types/react": "link:../node_modules/@types/react",
|
||||
"@types/react-dom": "link:../node_modules/@types/react-dom",
|
||||
"react": "link:../node_modules/react",
|
||||
"react-dom": "link:../node_modules/react-dom",
|
||||
"react": "^16.13.1",
|
||||
"react-dom": "^16.13.1",
|
||||
"react-scripts": "link:../node_modules/react-scripts",
|
||||
"typescript": "link:../node_modules/typescript",
|
||||
"base-context-provider": "link:.."
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import React from 'react'
|
||||
|
||||
import { ExampleComponent } from 'base-context-provider'
|
||||
import 'base-context-provider/dist/index.css'
|
||||
import {wrapTestProvider} from './TestContext'
|
||||
import Button from './Button'
|
||||
|
||||
const App = () => {
|
||||
return <ExampleComponent text="Create React Library Example 😄" />
|
||||
return <div>hello
|
||||
<Button/>
|
||||
</div>
|
||||
}
|
||||
|
||||
export default App
|
||||
export default wrapTestProvider(App)
|
||||
|
||||
15
example/src/Button.tsx
Normal file
15
example/src/Button.tsx
Normal file
@@ -0,0 +1,15 @@
|
||||
import React from 'react'
|
||||
import { useTestContext, withTestContext } from './TestContext'
|
||||
|
||||
const Button = (props: any) => {
|
||||
const {punishmentLevel} = props.testContextProps
|
||||
const { heat }: any = useTestContext()
|
||||
return (
|
||||
<div>
|
||||
heat: {heat} <br/>
|
||||
levels: {punishmentLevel}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default withTestContext(Button)
|
||||
33
example/src/TestContext.ts
Normal file
33
example/src/TestContext.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import React from 'react'
|
||||
import BaseContextProvider, {
|
||||
baseContextWrap,
|
||||
baseUseContext,
|
||||
baseWithContext
|
||||
} from 'base-context-provider'
|
||||
|
||||
const Context = React.createContext({})
|
||||
|
||||
class TestContextProvider extends BaseContextProvider {
|
||||
state = {
|
||||
heat: 5,
|
||||
punishmentLevel: 10
|
||||
}
|
||||
|
||||
getContextReturnValue() {
|
||||
return {
|
||||
...this.state
|
||||
}
|
||||
}
|
||||
|
||||
getContext() {
|
||||
return Context
|
||||
}
|
||||
}
|
||||
|
||||
export const useTestContext = baseUseContext(Context)
|
||||
|
||||
export const withTestContext = baseWithContext(Context, 'testContextProps')
|
||||
|
||||
export const wrapTestProvider = baseContextWrap(TestContextProvider)
|
||||
|
||||
export default TestContextProvider
|
||||
@@ -1,5 +1,4 @@
|
||||
import './index.css'
|
||||
|
||||
import React from 'react'
|
||||
import ReactDOM from 'react-dom'
|
||||
import App from './App'
|
||||
|
||||
@@ -2,7 +2,10 @@
|
||||
"compilerOptions": {
|
||||
"outDir": "dist",
|
||||
"module": "esnext",
|
||||
"lib": ["dom", "esnext"],
|
||||
"lib": [
|
||||
"dom",
|
||||
"esnext"
|
||||
],
|
||||
"moduleResolution": "node",
|
||||
"jsx": "react",
|
||||
"sourceMap": true,
|
||||
@@ -15,8 +18,21 @@
|
||||
"suppressImplicitAnyIndexErrors": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"allowSyntheticDefaultImports": true
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"target": "es5",
|
||||
"allowJs": true,
|
||||
"skipLibCheck": true,
|
||||
"strict": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"noEmit": true
|
||||
},
|
||||
"include": ["src"],
|
||||
"exclude": ["node_modules", "build"]
|
||||
"include": [
|
||||
"src"
|
||||
],
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
"build"
|
||||
]
|
||||
}
|
||||
|
||||
@@ -8687,9 +8687,15 @@ react-dev-utils@^10.2.1:
|
||||
strip-ansi "6.0.0"
|
||||
text-table "0.2.0"
|
||||
|
||||
"react-dom@link:../node_modules/react-dom":
|
||||
version "0.0.0"
|
||||
uid ""
|
||||
react-dom@^16.13.1:
|
||||
version "16.13.1"
|
||||
resolved "https://npm-registry.cubetiqs.com/react-dom/-/react-dom-16.13.1.tgz#c1bd37331a0486c078ee54c4740720993b2e0e7f"
|
||||
integrity sha512-81PIMmVLnCNLO/fFOQxdQkvEq/+Hfpv24XNJfpyZhTRfO0QcmQIF/PgCa1zCOj2w1hrn12MFLyaJ/G0+Mxtfag==
|
||||
dependencies:
|
||||
loose-envify "^1.1.0"
|
||||
object-assign "^4.1.1"
|
||||
prop-types "^15.6.2"
|
||||
scheduler "^0.19.1"
|
||||
|
||||
react-error-overlay@^6.0.7:
|
||||
version "6.0.7"
|
||||
@@ -8705,9 +8711,14 @@ react-is@^16.12.0, react-is@^16.8.1, react-is@^16.8.4:
|
||||
version "0.0.0"
|
||||
uid ""
|
||||
|
||||
"react@link:../node_modules/react":
|
||||
version "0.0.0"
|
||||
uid ""
|
||||
react@^16.13.1:
|
||||
version "16.13.1"
|
||||
resolved "https://npm-registry.cubetiqs.com/react/-/react-16.13.1.tgz#2e818822f1a9743122c063d6410d85c1e3afe48e"
|
||||
integrity sha512-YMZQQq32xHLX0bz5Mnibv1/LHb3Sqzngu7xstSM+vrkE5Kzr9xE0yMByK5kMoTK30YVJE61WfbxIFFvfeDKT1w==
|
||||
dependencies:
|
||||
loose-envify "^1.1.0"
|
||||
object-assign "^4.1.1"
|
||||
prop-types "^15.6.2"
|
||||
|
||||
read-pkg-up@^2.0.0:
|
||||
version "2.0.0"
|
||||
|
||||
Reference in New Issue
Block a user