sAleksovski / react-native-android-widget

Build Android Widgets with React Native

Home Page:https://sAleksovski.github.io/react-native-android-widget/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

how to get saved data from widget with react-native-async-storage/async-storage?

kimgh06 opened this issue · comments

Hello.

I enjoy your package, but there's a problem.

When I try to get async storage item using react-native-async-storage/async-storage from the widget handler,
the widget can not be resized and updated.

I could show my codes you read.

import React from 'react';
import { HelloWidget } from './HelloWidget';
import useStore from './store';

const nameToWidget = {
  // Hello will be the **name** with which we will reference our widget.
  Hello: HelloWidget,
};

export async function widgetTaskHandler(props) {
  const widgetInfo = props.widgetInfo;
  const Widget = nameToWidget[widgetInfo.widgetName];
  const { getAsyncItem } = useStore(s => s);
  const text= await getAsyncItem('text');

  switch (props.widgetAction) {
    case 'WIDGET_ADDED':
      props.renderWidget(<Widget text={text} />);
      break;

    case 'WIDGET_UPDATE':
      props.renderWidget(<Widget text={text} />);
      break;

    case 'WIDGET_RESIZED':
      props.renderWidget(<Widget text={text} />);
      break;

    case 'WIDGET_DELETED':
      // Not needed for now
      break;

    case 'WIDGET_CLICK':
      // Not needed for now
      break;

    default:
      break;
  }
}

I think there's a solution that I didn't think of.

How to get saved data from widget?

I will wait for your answer.

Thanks.

Oh, god.
I should not did use a custom hook using zustand.
I just tried with AsyncStorage hook, and It worked.

Sorry for wasting your time.