I'm really going crazy here and hoping someone can help me with this problem. I have the following code inside my model:
this.text = json.text ? json.text : ''
This sends the following warning in my inspector
Expected an assignment or function call and instead saw an expression no-unused-expressions
So I tried the following:
let text;
if(json.text) text = json.text
else text = ''
this.text = text
But this, strangely enough, still returns the same warning.
Can someone give me an explanation as to why this warning presents itself and what I should do to fix this? I would like to have a warning free web app.
Update: I cleaned up my code to make it more understandable for those who're not in the project. These are the two components that react with each other. For each item I get from my query, I go to the fromJSON method in my model. I push the returned value inside my results array and return that array.
Model.js
import BaseModel from './BaseModel'
export default class Model extends BaseModel {
constructor(){
super()
this.nis
this.postal
this.text
this.type
}
fromJSON(json) {
this.nis = json.nisCode ? json.nisCode : ''
this.postal = json.postal ? json.postal : ''
this.text = json.text ? json.text : ''
this.type = json.type ? json.type : ''
}
}
Service.js
import { BaseService } from './BaseService';
import Model from '../models/Model';
import Translation from '../components/_translations/Meta';
// To get content in correct language
const lang = new Translation().getContent('lang')
export default class Service extends Service {
async search(keyword, type = 'keyword', query) {
// Get the results data using the Axios instance
return this.axiosInstanceOsn.get(query).then(
value => {
// First and foremost, check if the call was successful
if (value.status === 200){
const data = value.data
let results = []
data.forEach(element => {
let as = new Model()
as.fromJSON(element)
results.push(as)
})
return results
}
}
)
}
}
Try this
import BaseModel from './BaseModel'
export default class Model extends BaseModel {
constructor(){
super()
this.nis = this.nis || ''
this.postal = this.postal || ''
this.text = this.test || ''
this.type = this.type || ''
}