Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Warning Reactjs – undefined

I working for one project to School and I have some problem with them.

So this is the code

`

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

import React from 'react';
import { AppBar, Container, Toolbar, Typography, MenuItem, Select, makeStyles, createTheme, ThemeProvider } from "@material-ui/core";
import { useNavigate } from "react-router-dom";
import { CryptoState } from '../CryptoContext';

//Creeare Design - Titlu
const useStyles = makeStyles(() => ({
  title: {
    flex:1,
    color: "gold",
    fontFamily: "Montserrat",
    fontWeight: "bold",
    cursor: "pointer",
  }
}))

const Header = () => {

  const classes = useStyles();
  const navigate = useNavigate();
  const {currency,setCurrency} = CryptoState() || {};
  

  console.log(currency);

  // TODO: Gandire sistem reintoarcere pagina principala 
  const handleClick = () => navigate.push('/'); // nu merge - reintoarcere la pagian principala


  // FIXME: Creeare template temă
  const darkTheme = createTheme({
    palette:{
      primary: {
        main: "#fff",
      },
      type: "dark",
    },
  });

  return (
    <ThemeProvider theme={darkTheme}>
      <AppBar color='transparent' position='static'>
          <Container>
            <Toolbar>
              <Typography onClick={handleClick} 
              className={classes.title} variant='h5'>Crypto Hunter</Typography>
              <Select variant="outlined" style={{
                width:100,
                height:40,
                marginLeft: 15,
              }}
              value={currency} onChange={(e) => setCurrency(e.target.value)}
              >
                <MenuItem value={"RON"}>RON</MenuItem>
                <MenuItem value={"EUR"}>EUR</MenuItem>
                <MenuItem value={"USD"}>USD</MenuItem>
              </Select>
            </Toolbar>
          </Container>
      </AppBar>
      </ThemeProvider>
  )
};

export default Header;

`

And this is the problem, I don’t know how I can fixed them.
What I want?

Image here

enter image description here

Please help me!

If I change from select with RON or USD or EURO, i want to console.log to can go to the next step.
But she give me this error (image), and i don’t know how i can fixed this’

EDIT:

Also, from CryptoState i have this code

    const Crypto = createContext();

const CryptoContext = ({children}) => {

 const [currency, setCurrency] = useState("RON");
 const [symbol, setSymbol] = useState("RON");

  useEffect(() => {
      if(currency === "RON") setSymbol("RON");
      else if(currency === "EUR") setSymbol("€");
      else if(currency === "USD") setSymbol("$");
  },[currency]);

return <Crypto.Provider value={{currency,symbol,setCurrency}}>{children}</Crypto.Provider>
};


export default CryptoContext;

export const CryptoState = () => {
    useContext(Crypto);
}

>Solution :

change that line

 const {currency,setCurrency} = CryptoState() || {};

to

 const [currency,setCurrency] =useState(CryptoState() || {}) ;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading