Parameters to be passed to the API when fetching quests.
The returning object contains:
fetched
: Boolean indicating whether the quests have been fetched from the API.quests
: List of quests with extended functionality.refresh
: FetchQuestsMethod Function to refresh the quests. Takes an optional
quiet
boolean.useState
to store the quests and a
fetched status.extendQuests
function augments each quest with additional
methods (complete
, delete
, push
).fetchQuests
method retrieves quests from the API, applies
caching, and extends them with additional methods.updateQuestState
, which
ensures state consistency.pushQuest
method updates a quest via the API and refreshes the local state.deleteQuest
method removes a quest via the API and updates local state to exclude it.complete
method marks a quest as complete and clears relevant cached data.useEffect
is used to automatically fetch quests when the params
change.import { useQuests } from 'react-playmakers';
const QuestComponent = () => {
const { fetched, quests, refresh } = useQuests({ key: 'example' });
if (!fetched) return <div>Loading...</div>;
return (
<div>
<h1>Quests</h1>
<ul>
{quests.map(quest => (
<li key={quest.id}>
{quest.name}
<button onClick={() => quest.complete({ creatorId:
'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX' })}>Complete</button>
<button onClick={quest.delete}>Delete</button>
<button onClick={() => quest.push({ name: 'Updated Quest Name' })}>Update</button>
</li>
))}
</ul>
<button onClick={() => refresh()}>Refresh Quests</button>
</div>
);
};
Generated using TypeDoc
Custom React hook to manage quests data.