使用react钩子导出布尔值



我有这个钩子,我需要导出一个带有布尔值的常量,这种方式就是发送一个字符串。

export const useType = () => {

const isFoo = 'string';
const isBar = 'other_string';

return { isFoo, isBar };
};

如何将其转换为布尔值?

我是新来的,如果有人能帮我,谢谢

我不确定我是否正确理解你的问题,但你是认真的吗?

export const useType = () => {

const isFoo = 'string';
const isBar = 'other_string';
const iAmBoolean = true;

return { isFoo, isBar, iAmBoolean };
};

假设您需要检查一个值是否是与isFoo和isBar等价的字符串。


export const useType = (props) => {
if(props === 'isFoo'){
return true
}else{
return false
}
}
//then you call useType(varWithTheString) to check if it's Foo or not.

最新更新