Skip to content

[Typo]: NOT operator in if-else #7473

Closed
@FSBalbuena

Description

@FSBalbuena

Summary

The code example on server functions with actions has an if checking for an error, but it has a NOT operator.

https://react.dev/reference/rsc/server-functions#server-functions-with-actions

according to the written code, the only returned value for updateName is an error, if there is no name.
Currently the code says "If there is no error, set error state to error" and it does not clean the name input.

"use client";

import {updateName} from './actions';

function UpdateName() {
  const [name, setName] = useState('');
  const [error, setError] = useState(null);

  const [isPending, startTransition] = useTransition();

  const submitAction = async () => {
    startTransition(async () => {
      const {error} = await updateName(name);
      if (!error) { // <---------------------------- we should delete the Not Operator
        setError(error);
      } else {
        setName('');
      }
    })
  }
  
  return (
    <form action={submitAction}>
      <input type="text" name="name" disabled={isPending}/>
      {state.error && <span>Failed: {state.error}</span>}
    </form>
  )
}

Page

https://react.dev/reference/rsc/server-functions#server-functions-with-actions

Details

The code example on server functions with actions has an if checking for an error, but it has a NOT operator.

https://react.dev/reference/rsc/server-functions#server-functions-with-actions

Inside the transition, we are checking for errors with an NOT operator.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions