import {useUnit} from 'effector-react'; import React, {useEffect, useRef} from 'react';…
- User
import {useUnit} from 'effector-react'; import React, {useEffect, useRef} from 'react';
import {SymbolInput} from '@/features/input-word/ui/symbol-input/index.jsx'; import * as styles from './word-input.module.css'; import {$userGuess} from '@/features/input-word/model/store.js'; import {checkUserGuess, initUserGuess} from "@/features/input-word/model/events.js";
export const WordInput = ({}) => { const userGuess = useUnit($userGuess); const triggerCheckUserGuess = useUnit(checkUserGuess);
const inputRefs = useRef([]);
const focusNextUnopenedSymbol = (currentIdx, step) => { for(let i = currentIdx + step; i >= 0 && i < userGuess.length; i += step) { if(!userGuess[i].isRevealed && inputRefs.current[i]) { inputRefs.current[i].focus(); return; } }
coderequestAnimationFrame(() => { inputRefs.current[currentIdx].focus(); })};
const focusNextSymbol = (currentIdx) => { focusNextUnopenedSymbol(currentIdx, 1); }
const focusPrevSymbol = (currentIdx) => { focusNextUnopenedSymbol(currentIdx, -1); }
useEffect(() => { const handleEnter = (event) => { if(event.key !== 'Enter') return; triggerCheckUserGuess(); }
codedocument.addEventListener('keydown', handleEnter); return () => document.removeEventListener('keydown', handleEnter);}, []);
return ( { userGuess.map(({idx, value, isRevealed}) => React.memo(<SymbolInput key={
${value}-${idx}} ref={el => inputRefs.current[idx] = el} idx={idx} value={value} isRevealed={isRevealed} focusNext={focusNextSymbol} focusPrev={focusPrevSymbol} />) )} ); }; Objects are not valid as a React child (found: object with keys {$$typeof, type, compare}). If you meant to render a collection of children, use an array instead. at throwOnInvalidObjectType (http://localhost:3000/bundle.js:19774:9) at createChild (http://localhost:3000/bundle.js:20026:7) at reconcileChildrenArray (http://localhost:3000/bundle.js:20291:25) at reconcileChildFibers (http://localhost:3000/bundle.js:20708:16) at reconcileChildren (http://localhost:3000/bundle.js:25839:28) at updateHostComponent () at beginWork () at HTMLUnknownElement.callCallback () at Object.invokeGuardedCallbackDev () at invokeGuardedCallback () после добавления react memo - Assistant