From f75e4529109640e39e527cdadda66d5e748ab1bf Mon Sep 17 00:00:00 2001 From: Jamie Kyle Date: Mon, 13 May 2019 16:31:32 -0700 Subject: add initialState --- README.md | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) (limited to 'README.md') diff --git a/README.md b/README.md index 7ad6ba6..1bbe281 100644 --- a/README.md +++ b/README.md @@ -45,8 +45,8 @@ import React, { useState } from "react" import { createContainer } from "unstated-next" import { render } from "react-dom" -function useCounter() { - let [count, setCount] = useState(0) +function useCounter(initialState = 0) { + let [count, setCount] = useState(initialState) let decrement = () => setCount(count - 1) let increment = () => setCount(count + 1) return { count, decrement, increment } @@ -69,7 +69,13 @@ function App() { return ( - + +
+
+ +
+
+
) } @@ -77,7 +83,6 @@ function App() { render(, document.getElementById("root")) ``` - ## API ### `createContainer(useHook)` @@ -107,6 +112,23 @@ function ParentComponent() { } ``` +### `` + +```js +function useCustomHook(initialState = "") { + let [value, setValue] = useState(initialState) + // ... +} + +function ParentComponent() { + return ( + + + + ) +} +``` + ### `Container.useContainer()` ```js @@ -500,7 +522,7 @@ I've intentionally published this as a separate package name because it is a com Please provide me with feedback on that migration process, because over the next few months I hope to take that feedback and do two things: - Make sure `unstated-next` fulfills all the needs of `unstated` users. -- Make sure `unstated` has a clean migration process towards `unstated-next`. +- Make sure `unstated` has a clean migration process towards `unstated-next`. I may choose to add APIs to either library to make life easier for developers. For `unstated-next` I promise that the added APIs will be as minimal as possible and I'll try to keep the library small. -- cgit v1.2.3