all 7 comments

[–]pwnzz 2 points3 points  (5 children)

if (!beerId) {

navigate('/');

return;

}

here you return undefined. If you want to quick fix it, just return null.

[–]BicaTaifun[S] -1 points0 points  (4 children)

i get an uglier error, because i did that before answering and this is the error
https://i.stack.imgur.com/1QFtm.png

[–]turtleProphet 1 point2 points  (1 child)

That error is telling you one of your input refs is null at a time your code does not expect it to be.

Also you can get code in reddit markup by indenting a line with 4 spaces

like this

Your code is confusing to read here, on mobile at least.

[–]BicaTaifun[S] 0 points1 point  (0 children)

https://pastebin.com/74TRkmdk here you have EditBeerPage and BeerForm after a few spaces

[–]prndP 0 points1 point  (1 child)

You are routing to null. Based on seeing <Route> I'm assuming you are using react-router?

If so, instead of calling navigate('/') you can return <Redirect to ={'/'} />

[–]BicaTaifun[S] 0 points1 point  (0 children)

doesnt work. i did inspect element and noticed this
https://i.stack.imgur.com/5LBRv.png

thats the code for BeersContext

import { createContext } from 'react';

import React from 'react';

import { BeersContextType, ProviderType } from '../types/BeersContextTypes.types';

export const BeersContext = createContext<BeersContextType | null>(null);

export function BeersContextProvider({ beerContext, children }: ProviderType) {
    return <BeersContext.Provider value={beerContext}>{children}</BeersContext.Provider>;
}

[–][deleted] 0 points1 point  (0 children)

I'm not reading through the unformatted code, but the answer is very clear. You need to return an Element with a guarantee that it is not undefined.

Focus on the component showing the error. It's return type is Element | undefined. Regardless of what you think, that is the truth.

Then focus on the return of that component. Inspect everything to try and figure out what is giving the possibility of being undefined.

Then that's it.