Skip to content

deferFn always resolves false #87

Closed
@wyqydsyq

Description

@wyqydsyq

deferFn should resolve the value of it's underlying promise, however it actually always resolves false:

	const { data, run, setData } = useAsync({
		initialValue: defaultContext,
		deferFn: customerLogin,
	});

	if (doLogin) {
		run(customerId).then(console.log);
	}

Logs false.

I would expect to get the object resolved by the Promise that customerLogin returns.

I want to be able to extract the value from the promise deferFn resolves, then call setData with the resolved response so the component re-renders with the new data e.g.

	const { data, run, setData } = useAsync({
		initialValue: defaultContext,
		deferFn: customerLogin,
	});

	if (doLogin) {
		run(customerId).then(customer => setData(customer));
	}

I need to use deferFn because I only want to run the promise conditionally, promiseFn (which does return the resolved value as expected) executes automatically so wouldn't work here, but I also want to get the data resolved from the deferred promise as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions