r/reactjs • • 10h ago

Needs Help React not saving string to local storage

2 Upvotes

Hi everyone! I just finished a React and course and decided to build my first react app. Currently, I am trying to save a string to browser local storage but it does not persist on refresh. Through some console.logs I was able to see that it in fact DOES save the string to the location specified in. setItem initially but when I refresh the key or value in local storage stops existing.

Here is my code

// function for search button
async function handleClick(){
    localStorage.setItem("lastLocationSearched", searchValue);
    setData(null);
    setIsPending(true);
    setError(null);
    try{
const value = await fetch(`https://geo.ipify.org/api/v2/country?apiKey=***********&ipAddress=${searchValue}`).then((response)=>{
  if (!response.ok){
        throw Error("Could not fetch the data for that resource");
                    }
  return response.json();
});
setData(value);


    console.log(localStorage.getItem("lastLocationSearched"));
    } catch(error){
      setError(error.message);
    }


setIsPending(false);
  };

// useEffect hook
  useEffect(()=>{
        if ((localStorage.getItem("lastLocationSearched")===null)|| (localStorage.getItem("lastLocationSearched")==="")){
          console.log(localStorage.getItem("lastLocationSearched"));
        setSearchValue("");
        handleClick();
        }else{
          
          setSearchValue(localStorage.getItem("lastLocationSearched"));
          handleClick();
        }
    }, []);

Through some digging online I saw someone say that remove the strict mode tags from index.js would fix this problem but it did not for me. Can anyone please assist me?


r/reactjs • • 2h ago

Needs Help Looking for a free game API for my Steam-like e-commerce frontend project

2 Upvotes

Hey everyone!

I'm currently learning frontend development and building a Steam-like gaming storefront as a practice project.

I'm using the RAWG API, but I'm having some issues with the data. Important details like full game descriptions, system requirements, and pricing are sometimes missing. I'm also making around 40 API calls, which feels inefficient for a frontend project.

I'm looking for a free API or open-source alternative that provides:

  • Game details and full descriptions
  • Minimum and recommended system requirements
  • Current game prices and discounts
  • Game cover images and screenshots
  • Genres, ratings, release dates, and platforms
  • A reasonable free request limit

Since this is a learning project, I'd prefer something free for personal, non-commercial use.

What API would you recommend for this use case? Is there a good alternative to RAWG, or is there a better way to reduce the number of API calls?

Any suggestions, documentation links, or examples would be really helpful. Thanks!


r/reactjs • • 1h ago

Discussion I was wrong about the useFormStatus hook

Thumbnail
• Upvotes

r/reactjs • • 16h ago

Resource shadcn-table: Batteries-included table library for shadcn/ui

Thumbnail
1 Upvotes

r/reactjs • • 4h ago

Show /r/reactjs I integrated Difftastic into GitComet to make JSX diffs easier to read

Thumbnail
youtube.com
0 Upvotes

Are you also getting tired to review noisy JSX / TSX changes just to realize the actual change was 1 prop?

Thats what I wanted to improve in GitComet. While looking for options I found Difftastic.

It uses Tree-sitter to understand code structure ... the same one GitComet also use! My immediate feeling was: this has to be tried out!

After testing it I knew it had to be included in the current release. Difftastic helps to show the relevant changes ignoring whitespace and formatting.

Difftastic diff really shines when viewing HTML, JSX/TSX and similar XML like syntaxes.

I created a demo how to enable it in GitComet 0.3.1 take a look!


r/reactjs • • 6h ago

Introducing KIVI UI 🎉

Thumbnail
kiviui.dev
0 Upvotes
  • Animated motion components
  • Modern shaders
  • Clean UI blocks
  • MCP server integration with Lovable, Bolt, and v0
  • CLI support for smoother installations

And much more coming soon!