For the easiest usage, the Crossword component is a simple drop-in component that provides a basic layout and the vast majority of the functionality.

src/Crossword.tsx

The default export from the react-crossword library, Crossword renders an answer grid and clues in a basic layout and provides access to most functionality.

*NOTE: Due to a shortcoming in react-docgen, the methods exposed via useImperativeHandle() are not currently getting documented. Here’s the missing documentation that should be in “Props & Methods” above:*

Method nameParametersDescription
focus()(none)Sets focus to the crossword component.
reset()(none)Resets the entire crossword; clearing all answers in the grid and also any persisted data.
fillAllAnswers()(none)Fills all the answers in the grid and calls the onLoadedCorrect callback with every answer.
isCrosswordCorrect()(none)Returns whether the crossword is entirely correct or not.
12

ACROSS

1: one plus one

DOWN

2: three minus two

See Clue input format for more details.

Player progress events

In addition to providing properties for styling, there are some properties to help your application “understand” the player’s progress:

propertydescription
onCorrectcallback function that fires when a player answers a clue correctly; called with (direction, number, answer) arguments, where direction is 'across' or 'down', number is the clue number as text (like '1'), and answer is the answer itself
onLoadedCorrectcallback function that’s called when a crossword is loaded, to batch up correct answers loaded from storage; passed an array of the same values that onCorrect would recieve
onCrosswordCorrectcallback function that’s called when the overall crossword is completely correct (or not)
onCellChangecallback function called when a cell changes (e.g. when the user types a letter); passed the row and column and the character typed
onClueSelectedcallback function called when a clue is selected; passed the direction and the “number”

Imperative methods

The following imperative methods can be called on a "ref" handle to the component:

method nameparametersdescription
focus()(none)Sets focus to the crossword component.
reset()(none)Resets the entire crossword; clearing all answers in the grid and also any persisted data.
fillAllAnswers()(none)Fills all the answers in the grid and calls the onLoadedCorrect callback with every answer.
isCrosswordCorrect()(none)Returns whether the crossword is entirely correct or not.
setGuess(row, col, guess)(row: number, col: number, guess: string)Sets the “guess” value for a specific grid position.

Clue direction labels

Providing the acrossLabel and/or downLabel properties will override the default "ACROSS" and "DOWN" used for the clues.

12

Lefty-righty

1: one plus one

Upsie-downsie

2: three minus two

Custom storage / multiple crosswords per-page

If you have more than one crossword at a given URL, you can use the storageKey property to provide a specific key under which to save the player's progress. (Just make sure to not set useStorage to false!)

Another example

Purely to show the grid rendering...

123456789101112131415161718192021222324252627

ACROSS

1: This
4: is
7: not
8: a
10: real
11: crossword,
12: it
13: is
16: only
19: showing
21: the
22: kind
23: of
25: thing
26: you
27: can

DOWN

1: create.
2: All
3: of
4: the
5: answers
6: are
9: "X"
11:
14:
15:
17:
18:
19:
20:
24:
25: