diff --git a/_lib_/react.tsx b/_lib_/react.tsx index c899811..9232813 100644 --- a/_lib_/react.tsx +++ b/_lib_/react.tsx @@ -77,11 +77,26 @@ const ProxyState =(argNew:StateType)=> // do we need to account for the function set? - function proxySetter (inArg:StateType) - { - const stateUser = {state:inArg, set:stateSet, reload:HMR.reloads}; - HMR.statesNew.set(id, stateUser); - stateSet(inArg); + function proxySetter ( inArg:StateType|((old:StateType)=>StateType) ) + { + const stateUser = {state:inArg as StateType, set:stateSet, reload:HMR.reloads}; + if(typeof inArg == "function") + { + //const passedFunction = inArg; + stateSet((oldState:StateType)=> + { + console.log("function setter intercepted"); + const output = inArg(oldState); + stateUser.state = output; + HMR.statesNew.set(id, stateUser); + return output; + }); + } + else + { + HMR.statesNew.set(id, stateUser); + stateSet(inArg); + } } return [stateGet, proxySetter]; diff --git a/example/app.tsx b/example/app.tsx index f86ad81..0bfecb5 100644 --- a/example/app.tsx +++ b/example/app.tsx @@ -4,18 +4,18 @@ import React from "react"; const CTXString = React.createContext("lol"); type StateBinding = [get:T, set:React.StateUpdater]; -const CTXState = React.createContext(null) as React.Context|null>; +const CTXState = React.createContext(null) as React.Context|null>; const Outer =(props:{children:VNode})=> { - const binding = React.useState("lol?"); + const binding = React.useState(11); return {props.children} }; const Inner =()=> { - const binding = React.useContext(CTXState); - return + const [stateGet, stateSet] = React.useContext(CTXState) || ["default", ()=>{}]; + return };