$form_state->setValue() doesn't save value I have an validate code:

public function validateForm(array &amp;$form, FormStateInterface $form_state) {
    parent::validateForm($form, $form_state);

    $form_state-&gt;setValue('my_variable', $form_state-&gt;getValue('my_variable') + 1);
    $form_state-&gt;setRebuild();
}


And I previously set my_variable to 1 if it's NULL:

public function buildForm(array $form, FormStateInterface $form_state) {

    if($form_state-&gt;getValue('my_variable') == NULL){
        $form_state-&gt;setValue('my_variable', 1);
    }
...


I use ajax callback for form submission and the validation works fine. After click on submit button I display my_variable and I see 2 (before submission it's 1). 

But when I hit the submit button again I see 2 again, instead of 3.
Also, when I re-load the page the data is missing (so it's get value 1 again).

How to prevail the value? It looks like I am operating on copy of $form_state instead of reference but I cannot write &amp;$form_state (public function validateForm(array &amp;$form, FormStateInterface &amp;$form_state)) because it gives me an error (as it's not the correct declaration of validateForm method).
If it is a custom variable, you should use $form_state-&gt;set('property_name', 'value') (instead of "$form_state-&gt;setValue(...)").

Example:

public function validateForm(array &amp;$form, FormStateInterface $form_state) {
    parent::validateForm($form, $form_state);

    // Update custom variable (in PHP "null + 1" equals one)
    $form_state-&gt;set('my_variable', $form_state-&gt;get('my_variable') + 1);

    // Below is only required when your "buildForm(...)" depends on the variable
    $form_state-&gt;setRebuild();
}