refact(404): convert link correction function to functional component

This commit is contained in:
Khinshan Khan
2020-01-26 12:38:28 -05:00
committed by Jean-Philippe Sirois
parent 8ab5ec1737
commit b154d0c515
3 changed files with 30 additions and 13 deletions
+14 -7
View File
@@ -1,6 +1,6 @@
import { WindowLocation } from "@reach/router"
import { Link } from "gatsby"
import React, { Fragment } from "react"
import React, { FC, Fragment } from "react"
import { FileConnection } from "../../../generated/graphql"
@@ -55,12 +55,19 @@ function levenshteinDistance(term1: string, term2: string) {
return matrix[term2.length][term1.length]
}
export const getPossibleCorrections = (
basepath: string,
location: WindowLocation,
data: { allFile: FileConnection },
threshold: number
) => {
interface IPossibleCorrections {
basepath: string
location: WindowLocation
data: { allFile: FileConnection }
threshold?: number
}
export const PossibleCorrections: FC<IPossibleCorrections> = ({
basepath,
location,
data,
threshold = 8,
}) => {
// the data prop has the graphql result
// we're abstracting it to `linkArray` to just have array of edges matched
// must use `.node.absolutePath` on each edge to get each node's absolute link