diff --git a/.eslintrc.cjs b/.eslintrc.cjs index f63bbef..7b85f4b 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -24,5 +24,6 @@ module.exports = { 'react/require-default-props': 'off', 'no-use-before-define': 'off', 'react/jsx-filename-extension': [1, { extensions: ['.ts', '.tsx'] }], + 'no-unused-vars': ['error', { argsIgnorePattern: 'api' }], }, }; diff --git a/src/index.tsx b/src/index.tsx index 317e5f6..4916cdf 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -8,11 +8,12 @@ interface Props { width?: number height?: number contained?: boolean; - config?: Config + config?: Config; + onApiReady?: (api: Api) => void; } function Chessground({ - width = 900, height = 900, config = {}, contained = false, + width = 900, height = 900, config = {}, contained = false, onApiReady, }: Props) { const [api, setApi] = useState(null); @@ -34,6 +35,12 @@ function Chessground({ api?.set(config); }, [api, config]); + useEffect(() => { + if (api && onApiReady) { + onApiReady(api); + } + }, [api]); + return (