Comparing version 0.31.0 to 0.31.1
{ | ||
"name": "actml", | ||
"version": "0.31.0", | ||
"version": "0.31.1", | ||
"description": "Like jsx but for your business logic", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -31,5 +31,6 @@ ![ActML](assets/logo.jpg) | ||
* [How to use it](#how-to-use-it) | ||
* [Caveats](#caveats) | ||
* [Introduction](#caveats) | ||
* [Children](#children) | ||
* [Asynchronous](#asynchronous) | ||
* [Context](#context) | ||
* [Hooks](#hooks) | ||
@@ -40,2 +41,3 @@ * [useState](#usestate) | ||
* [usePubSub](#usepubsub) | ||
* [useContext](#usecontext) | ||
* [Examples](#examples) | ||
@@ -138,2 +140,32 @@ | ||
### Context | ||
I can't say it better than [React docs](https://reactjs.org/docs/context.html#reactcreatecontext): | ||
> Context provides a way to pass data through the component tree without having to pass props down manually at every level. | ||
```js | ||
import { createContext } from 'actml'; | ||
const Context = createContext('<default value>'); | ||
const { Provider, Consumer } = Context; | ||
const F = () => { | ||
return ( | ||
<Consumer> | ||
{ value => console.log(value) } | ||
</Consumer> | ||
); | ||
}; | ||
run( | ||
<Provider value='foo'> | ||
<F /> | ||
</Provider> | ||
); | ||
// outputs: 'foo' | ||
``` | ||
ActML searches for the `<Provider>` up the tree from the place where the `<Consumer>` is positioned. If it can't find the `<Provider>` then it shows a warning and delivers `<default value>` instead. | ||
## Hooks | ||
@@ -231,2 +263,20 @@ | ||
### useContext | ||
Consume the value of a context. | ||
```js | ||
const Context = createContext(); | ||
const F = () => { | ||
const value = useContext(Context); | ||
// here value is 'foo' | ||
}; | ||
run( | ||
<Context.Provider value='foo'> | ||
<F /> | ||
</Context.Provider> | ||
); | ||
``` | ||
## Examples | ||
@@ -233,0 +283,0 @@ |
Sorry, the diff of this file is not supported yet
101457
281