reactfire icon indicating copy to clipboard operation
reactfire copied to clipboard

[FEATURE] Using a remote config value with a generic type

Open louis030195 opened this issue 2 years ago • 0 comments

When using JSON in remote config parameter, we have to parse by ourselves the JSON, could be cleaner with generic type?

Current usage

interface MyAwesomeRemoteConfigParameter {
    buttonColor: "blue" | "red";
    autoDestruction: boolean;
}

const {data: myParamJsonString} = useRemoteConfigString("my_awesome_remote_config_parameter");
const myParam: MyAwesomeRemoteConfigParameter | undefined = myParamJsonString ? 
    JSON.parse(myParamJsonString) :
    undefined;

Desired usage

interface MyAwesomeRemoteConfigParameter {
    buttonColor: "blue" | "red";
    autoDestruction: boolean;
}

const {data: myParam} = useRemoteConfigValue<MyAwesomeRemoteConfigParameter>("my_awesome_remote_config_parameter");
// myParam is parsed with MyAwesomeRemoteConfigParameter interface

louis030195 avatar Apr 04 '22 10:04 louis030195