Reputation: 1
I have a React component in two different projects:
Project A: A React project built with react-scripts build (Create React App). Project B: A Vite-based React project using vite build.
In both projects, I'm using the same component that consumes a context (ResultContext) and logs the result using console.log().
import React, { useContext } from 'react';
import { ResultContext } from './ResultContext'; // Custom context provider
import { Result } from './types'; // Assume Result is a type
const HelloSpace = (): React.ReactElement<any> => {
const result: Result = useContext(ResultContext);
console.log("result", result);
return (
<p>{result}</p>
);
};
export default HelloSpace;
Now i am installing these as packages(shared packages) in my main project and using the above component.
Issue: When using the component from Project A (CRA): The result is logged to the console and rendered on the screen as expected. When using the component from Project B (Vite): The result is an empty object.
please let me know if any additional details like vite.config.ts needed?
Upvotes: 0
Views: 28