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

[V4] Unable to access connected actions after migration #2934

Closed
alvarolorentedev opened this issue Mar 13, 2018 · 2 comments
Closed

[V4] Unable to access connected actions after migration #2934

alvarolorentedev opened this issue Mar 13, 2018 · 2 comments

Comments

@alvarolorentedev
Copy link

Version

Tell us which versions you are using:

  • react-native-router-flux v4.0.0-beta.28
  • react-native v0.53.3

Expected behaviour

i can connect the router and my components to have access to redux, so I have access to conected actions.

Actual behaviour

No access to redux actions.

Steps to reproduce

In version 3 i could define my routes and connect them to my action in the next way.

const scenes = Actions.create(
    <Scene key="root" hideNavBar={true} tabs={false} >
        <Scene key="tabbar" tabs={false} hideNavBar={true}>
            <Scene key='main' component={main} title="Main" initial/>
        </Scene>
     </Scene>
)

const RouterWithRedux = connect()(Router)

class AppContainer extends Component {
render() {
        return <RouterWithRedux {...this.props} scenes={scenes}/>
    }
}

function mapDispatchToProps(dispatch){
    return bindActionCreators(ActionCreators, dispatch)
}

export default connect(() => {return {}}, mapDispatchToProps)(AppContainer)

as you can see 2 things where happening the connection of the the definition of a connected Router that had the defined scenes and the connection of the main container to the set of available actions.

in any of the underlaying components if I have

<Button onPress={() => {
                    console.log(this.props.addToInventory)
                    this.props.addToInventory()
                }}><Text>Add</Text></Button>

it will print undefined.

what am i doing wrong? 🤔

@alvarolorentedev
Copy link
Author

so there seems to be a problem with Actions.create or the binding with the scene (there must be a small change there from v3).

class AppContainer extends Component {
    render() {
            return <Router {...this.props}>
                        <Scene key="root" hideNavBar={true} tabs={false} >
                            <Scene key="tabbar" tabs={false} hideNavBar={true}>
                                <Scene key='main' component={main} title="Main" />
                                <Scene key='inventory' component={inventory} title="Inventory" initial/>
                            </Scene>
                        </Scene>
                    </Router>
        }
    }

function mapDispatchToProps(dispatch){
    return bindActionCreators(ActionCreators, dispatch)
}

export default connect(() => {return {}}, mapDispatchToProps)(AppContainer)

removing create scenes and the connected router with redux worked for me, but i am still curious, on if this is by design and will it continue working on the future?

is this somehow related to migration point 1? (No component support for scene containers (that contains children Scene) - you have to use custom navigators (navigator prop) and possibly contentComponent (scenes cannot have both 'component' and 'children'))

@aksonov
Copy link
Owner

aksonov commented Aug 8, 2018

You are right, it was migration change, sorry.

@aksonov aksonov closed this as completed Aug 8, 2018
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

No branches or pull requests

2 participants