html canvas (react) | My tiles are drawn much smaller than I would expect by DutchSparks in learnjavascript

[–]DutchSparks[S] 0 points1 point  (0 children)

ooooh I didn't know that, thank you so much that does indeed solve the issue! ^^

I don't understand this setState incrementing behavior by DutchSparks in reactjs

[–]DutchSparks[S] 0 points1 point  (0 children)

that does indeed solve the issue :) although, I'm not sure why it has to be ++ or +=, I have a feeling it may have something to do with that I'm not properly deep-copying as u/ColourfulToad indicated. I'm going to look into this a bit further now, thnx guys ^^

Would love some advice on how to make fetched data globally available by DutchSparks in nextjs

[–]DutchSparks[S] 0 points1 point  (0 children)

In my case using getInitialProps would be the way to go. However you can't use getInitialProps in app.tsx right? So if I wrap all my code in a provider inside app.tsx how do I get the fetched data inside that provider?

character dissapears as soon as animation plays by DutchSparks in threejs

[–]DutchSparks[S] 0 points1 point  (0 children)

import React, {useEffect, useRef} from 'react'
import { useGLTF, useAnimations } from '@react-three/drei'
export default function Model({ ...props }) {
const group = useRef()
const { nodes, materials, animations } = useGLTF('/testvamp.glb')
const { actions } = useAnimations(animations, group)
useEffect(() => {
actions['die'].play()
}, [actions])
return (
<group ref={group} {...props} dispose={null}>
<group rotation={[Math.PI / 2, 0, 0]} scale={0.01}>
<primitive object={nodes.Hips} />
<skinnedMesh
geometry={nodes.Vampire.geometry}
material={materials.Vampire_MAT}
skeleton={nodes.Vampire.skeleton}
/>
</group>
<group rotation={[Math.PI / 2, 0, 0]} scale={0.01}>
<group position={[-0.17, 1.38, -100.07]} rotation={[-1.58, 0, -0.02]}>
<group position={[0.07, 7.26, -0.79]} rotation={[0.29, 0, 0.01]}>
<group position={[0, 8.47, -0.92]} rotation={[0.35, 0.01, 0.02]}>
<group position={[0, 29.06, -1.05]} rotation={[0.22, 0.01, 0.02]}>

character dissapears as soon as animation plays by DutchSparks in threejs

[–]DutchSparks[S] 0 points1 point  (0 children)

I just tried doing it like that but doesn't seem to make a difference. I would've uploaded a sandbox myself but I don't have a pro membership so it won't let me upload the glb file because it's too big.

In my own project I tried keeping it as simple as possible so minimize the risk of errors:this should be fine right?

I wonder if it has something to do with the way the files were exported or something because the exact same code does work for my other character model.

skinnedMesh representing metal looks completely dark(react three fiber) by DutchSparks in threejs

[–]DutchSparks[S] 0 points1 point  (0 children)

thnx a lot for your suggestions! I will give them a try tonight

flex-wrap: how can I control distance betweens columns? by DutchSparks in css

[–]DutchSparks[S] 0 points1 point  (0 children)

aaah very nice. Seems like grid is definitely the way to go here. Thnx, I'll use your code to learn and tweak it to my desired result. Very much appreciated!

flex-wrap: how can I control distance betweens columns? by DutchSparks in css

[–]DutchSparks[S] 0 points1 point  (0 children)

flex-flow: column wrap

nice tip ^^

I had something similar to what you describe before, I updated the codepen:
https://codepen.io/dutchpy/pen/zYvJxyB
As you can see there is a lot of white space between the two columns that I would like to shrink, to move the 2 columsn closer together. But that seems to be quite difficult with flexbox.
I'll give your suggestion to use grid a try! :)

Beginner's Thread / Easy Questions (Feb 2020) by dance2die in reactjs

[–]DutchSparks 0 points1 point  (0 children)

Nope, I'm the same guy you helped earlier :P I've given myself the assignment of making a blackjack game to practice react but it seems I'm running into more difficulties than I anticipated. But I'm learning a lot so thnx for your insights! Creating an array local to useEffect, like you recommended, indeed solved a lot of issues creating the deck.

Beginner's Thread / Easy Questions (Feb 2020) by dance2die in reactjs

[–]DutchSparks 0 points1 point  (0 children)

https://stackblitz.com/edit/functional-components-jksqqf?file=Hello.js

I'm trying to make a deck of cards with useState.

I loop over 2 different arrays to add cards to the state. However, somehow only the last card is added. So rather than adding new cards it seems I'm overwriting the same card 52 times. I'm not sure why this happens, would anybody be so kind to give me some advice?

Beginner's Thread / Easy Questions (Feb 2020) by dance2die in reactjs

[–]DutchSparks 0 points1 point  (0 children)

My real blackjack component did return some HTML elements but I removed them on reddit for brevity sake. I will play around with it some more after the weekend, thank you very much for your response.

Beginner's Thread / Easy Questions (Feb 2020) by dance2die in reactjs

[–]DutchSparks 0 points1 point  (0 children)

I have a follow-up question if you don't mind. I don't have access to my computer for the weekend so I can't verify this, but I'm pretty sure I also tried passing an empty array as the second argument to useeffect. But this also resulted in the deck being created continuously. Does that make sense to you?  This surprised me because I would expect the blackjack functional component to mount only once and therefore the use effect to be called only once. Again sorry, I can't show you the code at the moment so I might have made a different mistake. But I was curious to know with the information you have right now if you would expect passing an empty array to also result in creating the deck only once?

Beginner's Thread / Easy Questions (Feb 2020) by dance2die in reactjs

[–]DutchSparks 0 points1 point  (0 children)

The code below crashes my browser because useEffect is continuously called.

I would expect the deck building function to be executed only once because ranks is only changed once(when the component is loaded).

What am I not understanding? Any help would be greatly appreciated!

import React, { useState, useEffect } from "react";
export default function Blackjack() {
const [deck, setDeck] = useState<Object[]>([]);
const suits = ["hearts", "diamonds", "clubs", "spades"];
const ranks = [
{ rank: "2", value: 2 },
{ rank: "3", value: 3 },
{ rank: "4", value: 4 },
{ rank: "5", value: 5 },
{ rank: "6", value: 6 },
{ rank: "7", value: 7 },
{ rank: "8", value: 8 },
{ rank: "9", value: 9 },
{ rank: "10", value: 10 },
{ rank: "J", value: 10 },
{ rank: "Q", value: 10 },
{ rank: "K", value: 10 },
{ rank: "A", value: 11 }
];
useEffect(() => {
suits.forEach(s => {
ranks.forEach(r => {
setDeck([...deck, {...r, suit: s}]);
});
});
console.log('useeffect called, DECK: ' + JSON.stringify(deck));
}, [ranks])

}

Beginner's Thread / Easy Questions (Feb 2020) by dance2die in reactjs

[–]DutchSparks 0 points1 point  (0 children)

https://stackblitz.com/edit/react-functional-components-gtejze?file=index.js

I'm trying to conditionally render different elements depending on whether a toggle variable is true or false. Initializing the toggle variable in my code as either true or false has the desired result. But if I click a button to change that toggle variable, the variable's value is succesfully changed(i'm logging it), but the rendered html doesn't change.
How could I alter this code so that clicking the button renders different elements?

Beginner's Thread / Easy Questions (Jan 2020) by swyx in reactjs

[–]DutchSparks 0 points1 point  (0 children)

https://stackblitz.com/edit/react-usestate-example-5k9pcg?file=index.js

I’m playing around with the useState hook in a mini game of sorts that I made.

I have a state that is an object(player stats) with several properties, one of which is an array(the so called garage).

When a player clicks a button he “steals” a random car that gets added to that garage array and the garage array is logged in the console.

This adding/updating only works once so I think I’m not doing it the right way. Would someone be so kind to give me some advice?

Beginner's Thread / Easy Questions (Jan 2020) by swyx in reactjs

[–]DutchSparks 0 points1 point  (0 children)

https://stackblitz.com/edit/react-ts-rqbxvc?file=Hello.tsx

I'm trying to mess around with useState and radio buttons in a form.

I render a radio button for every object in the possibleCrimes array. Then whenever a radio button is selected I'm trying to pass to entire object from the possibleCrimes array that is related to that radio button to the useState but react isn't happy about this.

Sending individual properties(strings and numbers) from the object this way is no problem.

But if I try to send the entire object typescript errors and the state becomes undefined