Note: AI assistance was employed in crafting the code snippets and refining this article. The inspiration came from the article: “I’m Comic Sans, Asshole”.


Stop it. I said: “STOP. IT!”. Stupid. You have been re-rendering your TindasanaAI React component for the gazillionth time and the items you are selecting are always lost along the way. Well, it’s time to lift me up, asshole. You don’t understand why? Well, let me baby-feed this for you.

Check out the not-so-brilliant move of placing the state smack in the middle of the main component:

function TindasaAI() {
  const [selectedSequenceOptions, setSelectedSequenceOptions] = useState({
    theme_chakras: false,
    theme_season: false,
    // ... (other options)
  });

  const handleImageClick = (selection) => {
    // Update state logic
  };

  // Render your UI, use handleImageClick, and show selected options.
}

Boom. Every time you hop to the next stage of the app, you’re basically throwing your selectedSequenceOptions into a black hole. It’s like doing a yoga pose on your mat and when you want to move from one pose to the next, someone comes along and pulls the mat away from underneath your feet. Namaste, stupid.

Fucking lift me up, bro. Just create a wrapper component, save the state in the wrapper and let the child component do its thing and re-render as often as it wants, the state will be as stable as grandma’s Wi-Fi password (which is “password”).

Behold, the beauty of lifted state:

function TindasaAIWrapper() { // Uh, yeah, I love this nice wrapper
  const [selectedSequenceOptions, setSelectedSequenceOptions] = useState({
    theme_chakras: false,
    theme_season: false,
    // ... (rest of the options)
  });

  const handleImageClick = (selection) => {
    // Update state logic
  };

  return (
    <TindasaAI>
      handleImageClick={handleImageClick}
      selectedSequenceOptions={selectedSequenceOptions}
      // ... (other props)
    />
  );
}

function TindasaAI({ handleImageClick, selectedSequenceOptions }) {
  // Render your UI, use handleImageClick, and show selected options.
}

It’s like having your yoga mat placed in a central location in your studio, no matter which poses you choose or how many times you change it, the mat remains in the same spot, keeping your selections (or poses) consistent.

So don’t forget this. By lifting up state you create a central place for your state and make it more accessible and prevent unwanted state resets.

Thanks for the lift, bro.