ReactN setGlobal()/useGlobal() not working for me

Viewed 182

I'm trying to setGlobal() vars and objects in one page and retrieve them in the next page

StackOverflow.js

import React, {setGlobal, useGlobal, useEffect} from 'reactn'

setGlobal({
    myVar: '',
    myObj: {}
})

const StackOverflow = () => {
    const [myVar, setMyVar] = useGlobal('myVar')
    const [myObj, setMyObj] = useGlobal('myObj')

    useEffect(() => {
        setMyVar('Hello World')
        setMyObj({name: 'Mr Magoo'})       
    }, [])

    useEffect(() => {
        console.log("MyVar: ", myVar, "\nMyObj: ", myObj)
    }, [myVar, myObj])

    return (
        <div style={{padding: 10}}>
            <h2><a href="/stackOverflow2">Click me</a></h2>
        </div>
    )
}

export default StackOverflow

StackOverflow2.js

import React, {useGlobal} from 'reactn'


const StackOverflow2 = () => {
    const [myVar] = useGlobal('myVar')
    const [myObj] = useGlobal('myObj')

    return (
        <div style={{padding: 10}}>
            <h2>StackOverflow2</h2>
            <div>My Var: {myVar}</div>
            <div>My Obj: {myObj.name}</div>
        </div>
    )
}

export default StackOverflow2

I expect to be able to setGlobal() vars/objects on one page, and useGlobal() vars/objects in second page. I'm getting nothing.

0 Answers
Related