joshwcomeau / react-flip-move

Effortless animation between DOM changes (eg. list reordering) using the FLIP technique.
http://joshwcomeau.github.io/react-flip-move/examples
MIT License
4.09k stars 258 forks source link

Warning: Using UNSAFE_componentWillReceiveProps #253

Closed kaminskydeveloper closed 4 years ago

kaminskydeveloper commented 4 years ago

Hello I have problem with this warning, couldn't find a solution in google. index.js:1 Warning: Using UNSAFE_componentWillReceiveProps in strict mode is not recommended and may indicate bugs in your code. See https://fb.me/react-unsafe-component-lifecycles for details. Move data fetching code or side effects to componentDidUpdate. If you're updating state whenever props change, refactor your code to use memoization techniques or move it to static getDerivedStateFromProps. Learn more at: https://fb.me/react-derived-state Please update the following components: FlipMove

Here is my code.

`const Chat = () => { const [messages, setMessages] = useState(messagesData);

const [errors, setErrors] = useState(null);

const [inputValue, setInputValue] = useState('');

const handleChange = (event) => { setInputValue(event.target.value); };

const messagesEndRef = useRef(null);

const scrollToBottom = () => { messagesEndRef.current.scrollIntoView({ behavior: 'auto', block: 'end', inline: 'end', }); };

const sendMessage = (event) => { event.preventDefault();

if (inputValue !== '') {
  setMessages([
    ...messages,
    {
      id: uuid(),
      user_id: 1,
      client: true,
      patreon: false,
      message: inputValue,
    },
  ]);

  setInputValue('');
  setErrors(null);
  scrollToBottom();
} else {
  setErrors([{ message: 'Cannot be empty' }]);
}

};

useEffect(() => { scrollToBottom(); }, [messages]);

return (

{messages.map((message) => { return (
{message.patreon && ( )} {message.message} {message.client && ( )}
); })}