milomg / swc-plugin-jsx-dom-expressions

An SWC implementation of the SolidJS Dom Expressions compiler
56 stars 8 forks source link

Shared context cross components #21

Open NunoCruzSW opened 2 weeks ago

NunoCruzSW commented 2 weeks ago

I have Scenario with Translation Provider

So on one file

const TransContext = createContext<[TFunction, TransProviderActions]>();

export const useTransContext = () => useContext(TransContext);

function createTransContext(){
// some code
}
export const TransProvider: ParentComponent<{ instance?: i18n, options?: InitOptions }> = (props) => {
    return <TransContext.Provider
            value={createTransContext(props.instance || i18next, props.options )}
            children={props.children}
        />
};

On import useTransContext other nested component it returns null;

export function Trans(prop: TransProps) {

    const [t] = useTransContext(); // this returns null

    return <>{t(prop.key, prop.options) }</>
}