Search code examples
immutable.js

How set variable with condition with immutable.js


This code in typescript:

const b
if (a == true) {
   b = [1]
} else {
   b = [2]
}

how to convert above code to immutable.js ?


Solution

  • You have two options:

    let b
    if (a) {
       b = List([1])
    } else {
       b = List([2])
    }
    
    //or
    const b = a ? List([1]) : List([2])