This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useState } from 'react'; | |
interface WithStateProps { | |
children: ({ state, setState }: { state: number; setState: (x: number) => void }) => React.ReactNode; | |
} | |
export function WithState<P extends object>(Component: React.ComponentType<P>) { | |
return function WithStateComponent(props: P & WithStateProps) { | |
const [state, setState] = useState(0); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Add to your checkr.js file. | |
function avoidParentAndSiblingIndexImports({ fileExtension }, underline) { | |
if (fileExtension !== "js" && fileExtension !== "jsx") { | |
return; | |
} | |
const siblingImport = /from '\.\/';/g; | |
underline( | |
siblingImport, | |
"Avoid importing from sibling modules index.js", | |
"info" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Add to your checkr.js file. | |
function noModifyingUseStateDirectly( | |
{ fileExtension, fileContents }, | |
underline | |
) { | |
if (fileExtension !== "js" && fileExtension !== "jsx") { | |
return; | |
} | |
const useState = /const \[(.+), .+\] = useState\([\s\S]*?\);/g; | |
let useStateMatches; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Add to your checkr.js file. | |
function mismatchedUseStateNames({ fileExtension, fileContents }, underline) { | |
if (fileExtension !== "js" && fileExtension !== "jsx") { | |
return; | |
} | |
const useState = /const \[(.+), (.+)\] = useState\([\s\S]*?\);/g; | |
let useStateMatches; | |
while ((useStateMatches = useState.exec(fileContents)) != null) { | |
const line = useStateMatches[0]; |