How do I use the states API in a hook? I'm trying to use the states API in Drupal 8 but I'm having trouble, and I'm also having difficult debugging.

Use case:

On user accounts, I have a taxonomy term reference field called Gender.  The three terms in the taxonomy vocabulary are female, male, and other.

I also have a text field on user accounts called Other.  I want to show this Other field if and only if Gender is set to other (term ID: 27).

Here is the code I'm using:

function mymodule_form_user_register_form_alter(&amp;$form, &amp;$form_state, $form_id) {
  $form['field_gender_other']['#states'] = array('visible' =&gt;
    array('input[name="field-gender"]' =&gt; array('value' =&gt; '27'),
    ),
  );
}


I based this off of code I used for Drupal 7.  Unfortunately, it's not doing anything.

I looked at StateDemo.php in the fapi submodule of the Examples module for Drupal 8, but that's for building a new form, and I'm trying to modify an existing form.
You should use like below:

$form['field_popin_text']['#states'] = [
  'visible' =&gt; [
    'select[name="NAME_OF_SELECT_LIST"]' =&gt; ['value' =&gt; '27'],
  ]
];