useGuesses

The useGuess hook is responsable for interact with the locally stored guessed, process then and calculate if the user won/lost

Type reference

Standardize a guess

import { useGuesses } from '@arti-the-ai/arti-core';
const { standardizeGuess } = useGuesses();

const standardizedGuess = standardizeGuess(`guEsS-
   *
   * not-standardized###@!`).then(console.log);
console.log(standardizedGuess);
// 'guess-not-standardized

Get game guesses

If you do not inform the gameId parameter, it will look for the active game in LocalStorage and return those guesses

import { useGuesses } from '@arti-the-ai/arti-core';
const { getGuesses } = useGuesses();

const guesses = getGuesses(
  '69cdde90-49da-4b84-86f0-c4b670a57047' //optional
).then(console.log);
// [] as Array<IProcessedGuess>
// Check the reference

Process a guess

import { useGuesses } from '@arti-the-ai/arti-core';
const { processGuess } = useGuesses();

const processedGuess = processGuess(
  'disco dance shark rice pizza water',
  {
    gameId: '69cdde90-49da-4b84-86f0-c4b670a57047', //optional
    maxWords: 3, // optional, 3 is the default value
  }
).then(console.log);
/* 
{
  guess: "disco dance shark",
  lives: 4,
  words: {
    correct: ["disco", "dance", "shark"];
    incorrect: ["rice pizza"];
    approximated: ["water"];
    alreadyGuessed: [];
  },
  hasWon: true,
  hasLost: false,
} as IProcessedGuess
*/

Last updated