Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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];
}
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);
}
const SearchForm: React.FC = () => {
const [value, setValue] = useSearch();
const search = useAction('triggerSearch');
return (
<form> {
search(value, true);
return ev.preventDefault();
}}>
<input placeholder="Search" type="search"> setValue(e.target.value)} value={value} />
);
};
</form>