"use client";

import { setUser } from "@/utils/store/features/ui/userdata.slice";
import React, { memo, useEffect } from "react";
import { useDispatch } from "react-redux";

const ComponentProvider = ({ children, userData }) => {
  const dispatch = useDispatch();

  // set user data to state
  useEffect(() => {
    if (userData) {
      dispatch(setUser(userData));
    }
  }, [userData, dispatch]);

  return <>{children}</>;
};

const UserProvider = memo(ComponentProvider);
export default UserProvider;
