How to use the piral-core.useAction function in piral-core

To help you get started, we’ve selected a few piral-core 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 smapiot / piral / src / packages / piral-feeds / src / useFeed.ts View on Github external
export function useFeed(options: ConnectorDetails): [boolean, TData, any] {
  const { loaded, loading, error, data } = useGlobalState(s => s.feeds[options.id]);
  const load = useAction('loadFeed');

  useEffect(() => {
    if (!loaded && !loading) {
      load(options);
    }
  }, [loaded]);

  return [loaded, data, error];
}
github smapiot / piral / src / packages / piral-forms / src / useForm.ts View on Github external
export function useForm(
  initialData: TFormData,
  history: History,
  options: InputFormOptions,
  existingId?: string,
) {
  const { silent, message } = options;
  const [id] = useState(existingId || generateId);
  const state = useGlobalState(m => m.forms[id] || createDefaultState(initialData));
  const updateState = useAction('updateFormState');
  usePrompt(!silent && state.changed, history, message);
  useEffect(() => {
    updateState(id, state, {
      active: true,
    });

    return () =>
      updateState(id, state, {
        active: false,
      });
  }, [state.submitting]);
  return createProps(id, state, updateState, options);
}
github smapiot / piral / src / samples / sample-piral-core / src / index.tsx View on Github external
const SearchForm: React.FC = () => {
  const [value, setValue] = useSearch();
  const search = useAction('triggerSearch');

  return (
    <form> {
        search(value, true);
        return ev.preventDefault();
      }}&gt;
      <input placeholder="Search" type="search"> setValue(e.target.value)} value={value} /&gt;
      
    
  );
};
</form>