Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor useEffect dependencies in PreviewComponent #10

Merged
merged 1 commit into from
Oct 24, 2024

Conversation

Atlessc
Copy link
Contributor

@Atlessc Atlessc commented Oct 24, 2024

fixed issue #9

approach:

removed the "color" state from the first useEffect dependency at Line 77 and added the code below to set the material color when the color state changes when a user clicks a color in the ColorPicker component:

	const updateMaterialColor = (hexColor: number) => {
		if (meshRef.current) {
			const material = new THREE.MeshStandardMaterial({ color: hexColor });
			meshRef.current.material = material;
		}
	};

	useEffect(() => {
		if (modelLoaded) {
			updateMaterialColor(parseInt(color.replace("#", ""), 16));
		}
	}, [color]);

tested the new changes in local env, network showing only the one fetch for the model, helping reduce api requests by 90%.

Copy link
Collaborator

@benhalverson benhalverson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stanley Thumb

@benhalverson benhalverson merged commit 47980c3 into Pyramid-S-C-H-E-M-E-for-short:main Oct 24, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants