Home > Mobile >  Passing props to attributes react js
Passing props to attributes react js

Time:10-01

const [mode_,setmode]=useState("dark")
<NavBar title="TextUtils" about="About TextUtils" mode={mode_} />

the code below is not working, when i console.log(props.mode) it outputs required string but there is no change in the Navbar component
when i view it from the browser its <nav > instead of <nav >

//Inside NavBar

<nav className={'navbar navbar-expand=lg navbar-${props.mode} bg-${props.mode}'} > 

CodePudding user response:

Use a template literal instead of a string literal, i.e. "`" instead of "'".

const props = { mode: "dark" };

console.log('navbar navbar-expand=lg navbar-${props.mode} bg-${props.mode}');
console.log(`navbar navbar-expand=lg navbar-${props.mode} bg-${props.mode}`)

Code:

<nav className={`navbar navbar-expand=lg navbar-${props.mode} bg-${props.mode}`}>
  • Related