Subscribe on changes!

The state of ref in functional components cannot be changed

avatar
Nov 12th 2020

Version

3.0.2

Reproduction link

https://jsfiddle.net/starfishing/6zc71eth/1/

Steps to reproduce

Declare subcomponent ButtonDemo in a new js file, Introduce child components in parent components。click child component and watch value change

What is expected?

value Increase

What is actually happening?

The component is re-rendered every time and overwrites the modified value

avatar
Nov 12th 2020
  1. browsers don't support jsx
  2. in html you need to use kebab-case for tag names
  3. move value = Vue.ref(1) outside the render function or don't use functional components

https://jsfiddle.net/bpzsqf2k/

avatar
Nov 12th 2020
  1. browsers don't support jsx
  2. in html you need to use kebab-case for tag names
  3. move value = Vue.ref(1) outside the render function or don't use functional components

https://jsfiddle.net/bpzsqf2k/

Does the function component support ref or other ways to maintain its own state, like react useState in function component

avatar
Nov 12th 2020

maintain its own state,

functional components in Vue are stateless