question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

allow passing props to Board from Client?

See original GitHub issue

it 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:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:12 (12 by maintainers)

github_iconTop GitHub Comments

3reactions
scallycommented, Mar 26, 2018

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?

0reactions
nicolodaviscommented, Mar 27, 2018

Thanks! Merged.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found