How to use the @tarojs/taro.useState function in @tarojs/taro

To help you get started, we’ve selected a few @tarojs/taro examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github NervJS / taro-v2ex-hooks / src / pages / thread_detail / thread_detail.tsx View on Github external
function ThreadDetail () {
  // const { loading, replies, topic, content } = this.state
  const [ topic ] = useState(GlobalState.thread)
  const [ loading, setLoading ] = useState(true)
  const [ replies, setReplies ] = useState([])
  const [ content, setContent ] = useState('')

  useAsyncEffect(async () => {
    try {
      const id = GlobalState.thread.tid
      const [{ data }, { data: [ { content_rendered } ] } ] = await Promise.all([
        Taro.request({
          url: api.getReplies({
            'topic_id': id
          })
        }),
        Taro.request({
          url: api.getTopics({
            id
github NervJS / taro-v2ex-hooks / src / pages / thread_detail / thread_detail.tsx View on Github external
function ThreadDetail () {
  // const { loading, replies, topic, content } = this.state
  const [ topic ] = useState(GlobalState.thread)
  const [ loading, setLoading ] = useState(true)
  const [ replies, setReplies ] = useState([])
  const [ content, setContent ] = useState('')

  useAsyncEffect(async () => {
    try {
      const id = GlobalState.thread.tid
      const [{ data }, { data: [ { content_rendered } ] } ] = await Promise.all([
        Taro.request({
          url: api.getReplies({
            'topic_id': id
          })
        }),
        Taro.request({
          url: api.getTopics({
            id
          })
        })
github NervJS / taro-v2ex-hooks / src / pages / thread_detail / thread_detail.tsx View on Github external
function ThreadDetail () {
  // const { loading, replies, topic, content } = this.state
  const [ topic ] = useState(GlobalState.thread)
  const [ loading, setLoading ] = useState(true)
  const [ replies, setReplies ] = useState([])
  const [ content, setContent ] = useState('')

  useAsyncEffect(async () => {
    try {
      const id = GlobalState.thread.tid
      const [{ data }, { data: [ { content_rendered } ] } ] = await Promise.all([
        Taro.request({
          url: api.getReplies({
            'topic_id': id
          })
        }),
        Taro.request({
          url: api.getTopics({
            id
          })
github SolidZORO / leaa / packages / leaa-miniprogram / src / pages / article / _components / ArticleList / ArticleList.tsx View on Github external
export const ArticleList = () => {
  const [getArticlesVariables, setGetArticlesVariables] = useState({
    page: 1,
    pageSize: 100,
    orderSort: 'DESC',
    orderBy: 'id',
  });
  const [getArticlesQuery, setGetArticlesQuery] = useState<{ articles: ArticlesWithPaginationObject }>();
  const [getArticlesLoading, setGetArticlesLoading] = useState(false);

  useEffect(() => {
    setGetArticlesLoading(true);

    apolloClient
      .query({
        query: GET_ARTICLES,
        variables: getArticlesVariables,
        fetchPolicy: 'network-only',
      })
      .then(({ data, loading }) => {
        console.log('THEN', loading);

        setGetArticlesQuery(data);
      })
      .catch(error => {
github NervJS / taro-v2ex-hooks / src / pages / index / index.tsx View on Github external
function Index () {
  const [ loading, setLoading ] = useState(true)
  const [ threads, setThreads ] = useState([])
  useAsyncEffect(async () => {
    try {
      const res = await Taro.request({
        url: api.getLatestTopic()
      })
      setLoading(false)
      setThreads(res.data)
    } catch (error) {
      Taro.showToast({
        title: '载入远程数据错误'
      })
    }
  }, [])

  return (
github Miaonster / taro-code / src / components / Barcode / index.js View on Github external
function BarCode({ text, scale, width, height }) {
  const [image, setImage] = useState('')

  useEffect(() => {
    if (text) {
      setImage(utils.barcode({ text, scale }))
    } else {
      setImage('')
    }
  }, [text, scale])

  const widthString = width ? width + 'px' : ''
  const heightString = height ? height + 'px' : ''
  const style = { width: widthString, height: heightString }
  return <img src="{image}" style="{style}">
}
github zhixiaoqiang / taroCloud / src / hooks.js View on Github external
export function useState (initState) {
  const [state, setState] = Taro.useState(initState)

  const setComboState = newState => {
    if (isObject(newState)) {
      setState(prevState => {
        return { ...prevState, ...newState }
      })
    } else {
      setState(newState)
    }
  }
  return [state, setComboState]
}
github NervJS / taro-v2ex-hooks / src / pages / node_detail / node_detail.tsx View on Github external
function NodeDetail () {
  const [ loading, setLoading ] = useState(true)
  const [ threads, setThreads ] = useState([])

  useLayoutEffect(() =&gt; {
    const { full_name } = this.$router.params
    Taro.setNavigationBarTitle({
      title: decodeURI(full_name)
    })
  }, [])

  useAsyncEffect(async () =&gt; {
    const { short_name } = this.$router.params
    try {
      const { data: { id } } = await Taro.request({
        url: api.getNodeInfo({
          name: short_name
        })
github fjc0k / vtils / packages / taro / src / hooks / useScope.ts View on Github external
export function useScope(): Component['$scope'] {
  const [scope, setScope] = useState()
  useDidShow(function (this: Component) {
    setScope(this.$scope)
  })
  return scope
}
github NervJS / taro-todomvc-hooks / src / store / store.js View on Github external
export function useStore (store) {
  const [ state, setState ] = useState(store.get())

  function updateState () {
    setState(store.get())
  }

  useEffect(() => {
    store.subscribe(updateState)
    return () => store.unsubscribe(updateState)
  })

  return state
}