import { useEffect } from 'react'; import type { SeoEditorEnv } from '../env'; import { useLiveAnalysis } from '../hooks/use-live-analysis'; import { setLiveScore } from '../lib/live-score'; /** * The score of the post as it is edited, for the toolbar button and the * save, whether the sidebar is open or not: closed, the toolbar showed the * stored score, stale or a red 0 on a post never scored, until it opened. * * @param props - Component props. * @param props.env - The editor's environment. * @return Nothing: it only keeps the score. */ export const LiveScore = ({ env }: { env: SeoEditorEnv }): null => { const { analysis } = useLiveAnalysis(env); const score = analysis && !analysis.needsKeyword ? analysis.score : null; useEffect(() => { setLiveScore(score); }, [score]); return null; };