Semicolon usage with 'use client' vs 'use server' ?
Answered
Pyrenean Mountain Dog posted this in #help-forum
Pyrenean Mountain DogOP
When looking at the documentation I see that ['use client'](https://nextjs.org/docs/app/building-your-application/rendering/client-components) does not get a semicolon at the end of it but ['use server'](https://nextjs.org/learn/dashboard-app/mutating-data#2-create-a-server-action) does. Is this just optional (the way using a semicolon with modern js is optional and not necessary) and what I'm seeing is a personal preference or is it really the case that one uses it while the other does not?
Actually I just saw where one example uses a semicolon at the end of 'use server' and the other does not. Compare [Server Components](https://nextjs.org/docs/app/building-your-application/data-fetching/server-actions-and-mutations#server-components) with [Create a Server Action](https://nextjs.org/learn/dashboard-app/mutating-data#2-create-a-server-action)
So then is a semicolon at the end of 'use client' legal? Is it option in either case ('use server' or 'use client)?
Actually I just saw where one example uses a semicolon at the end of 'use server' and the other does not. Compare [Server Components](https://nextjs.org/docs/app/building-your-application/data-fetching/server-actions-and-mutations#server-components) with [Create a Server Action](https://nextjs.org/learn/dashboard-app/mutating-data#2-create-a-server-action)
So then is a semicolon at the end of 'use client' legal? Is it option in either case ('use server' or 'use client)?
14 Replies
Pyrenean Mountain DogOP
Is
'use server'; a typo in https://nextjs.org/learn/dashboard-app/mutating-data#2-create-a-server-action@Pyrenean Mountain Dog Is `'use server';` a typo in https://nextjs.org/learn/dashboard-app/mutating-data#2-create-a-server-action
semicolons are optional in javascript
Answer
@Ray semicolons are optional in javascript
Pyrenean Mountain DogOP
So
use client and use server are actually javascript and not something else?For some reason it doesn't seem to resemble js syntax (unless you call it a string literal or something).
It’s similar to “use strict†https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode
@joulev It’s similar to “use strict†https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode
Pyrenean Mountain DogOP
Ohhh.. ok. Hmm.. makes me even more curious what next is doing under the hood with things like that but ok.
@joulev It’s not next. It’s a react thing. https://react.dev/reference/react/use-client#noun-labs-1201738-(2)
Pyrenean Mountain DogOP
I thought
use client was a next thing whereas use server was a react thingoh wait - I see what its saying - I stand corrected. Thanks for pionting that out
@Pyrenean Mountain Dog I thought `use client` was a next thing whereas `use server` was a react thing
No, both are react features. All frameworks supporting server components will support both of them
Pyrenean Mountain DogOP
I thought react was only client side tho
Nextjs doesn’t have any directives of its own
Pyrenean Mountain DogOP
ok
I need to get familiar w/ this then