react-input-emoji icon indicating copy to clipboard operation
react-input-emoji copied to clipboard

How can i set a default value in InputEmoji , it is always the value set as " "

Open louayyahyaoui opened this issue 4 years ago • 5 comments

<InputEmoji value={text} onChange={setText} cleanOnEnter placeholder="Votre commentaire ici ..." onEnter={handleUpdateComment} />

the text variable contain a value for example "Hello there" but it didnt display in the input

louayyahyaoui avatar Jan 04 '22 14:01 louayyahyaoui

did you get any solutions @louayyahyaoui

kamran08 avatar Jun 12 '22 08:06 kamran08

@louayyahyaoui bro, did you get this issue resolved, I am still having the same problem.

farhadhabibi avatar Jun 26 '22 22:06 farhadhabibi

Sorry but i didnt get any solution yet

louayyahyaoui avatar Jun 27 '22 01:06 louayyahyaoui

@farhadhabibi you need to use 'useRef', for example ` const emojiRef = useRef();

useEffect(() => {
    emojiRef.current.value = YOUR_DEFAULT_DATA;
}, []);

return (
        <InputEmoji ref={emojiRef} />
);

`

PavelLazarchuk avatar Jul 18 '22 14:07 PavelLazarchuk

@PavelLazarchuk, thank you bro it helps me alot, could you please tell me why I should use 'useEffect' since I tried to make it without useEffect but it did not work?

farhadhabibi avatar Jul 25 '22 20:07 farhadhabibi

Just use value from the useState hook and pass it to the value prop of the <InputEmoji/> component.

const App = () => {
    const [message, setMessage] = useState<string>("default message");
    
    return (
        <InputEmoji value={message} />
    );
}

P.S: I've tested this option. And when I tried to set the default message this way - it works fine.

xNevrroXx avatar Oct 29 '23 18:10 xNevrroXx