Skip to content

Instantly share code, notes, and snippets.

@ondrek
Last active April 15, 2021 19:42
Show Gist options
  • Save ondrek/e944b25ca4e13a1c67f2031f61a91270 to your computer and use it in GitHub Desktop.
Save ondrek/e944b25ca4e13a1c67f2031f61a91270 to your computer and use it in GitHub Desktop.
// hook file
function Hook() {
const [ value, setValue ] = useState(null)
return {
secret: {
value,
fetch: (params) => post("/url", params).then(setValue)
}
}
}
// react component
function Element {
const { secret } = useInterface()
function fetchSecret() {
secret.fetch({ parameter: 123 })
}
console.info(secret.value)
}
// api file
export function postToSecret(params) {
return post("/url", params)
}
// react component
function Element {
const [ value, setValue ] = useState(null)
function fetchSecret() {
postToSecret({ parameter: 123 }).then(setValue)
}
console.info(value)
}
@ondrek
Copy link
Author

ondrek commented Apr 15, 2021

</Route>
    <ProvideAuth>
      <ProvideInterface>
        <Switch>
          <Route path="/action">
            <ActionRouting />
          </Route>
          <Route exact path="/new">

@ondrek
Copy link
Author

ondrek commented Apr 15, 2021

const abc = useApi.accounts.fetch()
{ isPending || data } 

@zboro
Copy link

zboro commented Apr 15, 2021

  const useQuery = (entity) => {
    const [data, setData] = useState();
    fetch(entity).then((x) => setData(x))
    return { data }
  }

useApi() { 
  return {
    account: useQuery(entity)
  }}

@zboro
Copy link

zboro commented Apr 15, 2021

const {data} = useApi().account.fetch()

@ondrek
Copy link
Author

ondrek commented Apr 15, 2021

// hook

const account = (params) => {
  const [ data, setData ] = useState()
  post("/posts/create", params).then(x => setData(x))
  return { data }
}

function useWorkspaceCheck(): Hook {
  return {
    account
  }
}

// component

function onButtonClicked() {
    const abc = account({ param: 124 })
    console.info(abc)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment