allow passing props to Board from Client?
See original GitHub issueit would be very useful for my flow if i could pass a function into the Board component as a prop, maybe through the config object passed to Client? ie:
class MyGame extends React.Component {
state = {numPlayers: 0}
render(){
const resetGame = () => this.setState({numPlayers: 0})
const GameClient = Client({game, board, resetGame, debug: false, numPlayers: this.state.numPlayers})
return this.state.numPlayers === 0 ? (<PickPlayersComponent />) : (<GameClient />)
}
}
so in my Board component i could do this.props.resetGame()
to completeley reset the whole flow.
or to just update the parent for any reason, (for me its so i can restart the game flow, but it could be for anything) i initially tried the provided reset function, but i need the entire Client component reset, so the number of players can be updated, since i dont believe there is anyway currently to dynamically update that value, i will submit a pull request to allow passing props through the Client, thoughts ideas?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:12 (12 by maintainers)
Top Results From Across the Web
allow passing props to Board from Client? · Issue #172 - GitHub
FWIW, I am using React context to accomplish this same thing (passing props into Board from outside), although I suspect just modifying the...
Read more >How passing props to component works in React
Master how to pass props (properties) to components in React with this useful beginner's guide, including demo code.
Read more >Passing Props to a Component - React Docs
Step 1: Pass props to the child component. First, pass some props to Avatar . For example, let's pass two props: person (an...
Read more >passing prop server-side is not being rendered client-side
Lets call {exists: true} the initial state. 1. On the server: Serialize the initial state using JSON.stringify and store it in the jade ......
Read more >Introduction to React Props & How to Use It in Your Code
Props work through passing data into a component to be used, typically for ... This can sound a little confusing, so let's look...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
FWIW, I am using React context to accomplish this same thing (passing props into Board from outside), although I suspect just modifying the HOC to accept props would be a more elegant solution.
It does also make me wonder how other people are handling app state outside of what boardgame.io offers. Another separate Redux store? Context? Ensuring everything is expressed via flow/moves?
Thanks! Merged.