When and how to use semi colons in react js(and when not to)

Viewed 2850

Hey I am beginner in react js and in the field of web dev. Can someone give a thumb rule or tricks to identify when to use a semi colon and when not to. For eg- in a demo code , one component had a semicolon in return function while the other dint (both were const function) and when I swapped the semi colons in both components the app crashed. Thanks in advance

without semicolon

import React from 'react'

const Notification=()=>{
    return(
        <div>
            <p>Notification</p>
        </div>    
       
    )
}
export default Notification

with semicolon

import React from 'react'
import {Link, NavLink} from 'react-router-dom'
import Navbar from './Navbar'

const Sighnedlinks=()=>{
    return(    
        <ul className="right">
            <li><NavLink to="/">Add New Project</NavLink></li>
            <li><NavLink to="/">Log Out</NavLink></li>
            <li><NavLink to="/" className="btn btn-floating pink lighten-1">NN</NavLink></li>
        </ul>

    );
}
export default Sighnedlinks
2 Answers

Yes, semicolons are important to use in JS, but as you start working with React you realize that usage of semicolons at certain line of code will throw you an error. So, it's not mandatory to use semicolon in React.

Semi colons are mostly optional but it's always safer to use it. Not specifically in react but in javascript in general.

Related