Code Monkey home page Code Monkey logo

Comments (6)

alinz avatar alinz commented on August 23, 2024

@albertwchang For simple and small project you can keep passing the ref to menuActions to your child components. I wouldn't recommend of doing this for mid or larger projects. You should use flux, reflux or any system that decouple these actions. if you need more help I can provide you a simple example.

p.s. I've been using refluxjs heavily in one big project contains 30 scenes and lots of animations. It's worth investing to those kind of frameworks.

from react-native-side-menu.

kevinaltschuler avatar kevinaltschuler commented on August 23, 2024

@alinz
how did you pass menuactions? the only way i see passing it right now is through menu, but there must be a way to also pass it to the child of sidemenu.

from react-native-side-menu.

alinz avatar alinz commented on August 23, 2024

Sorry for long delay, @Kevtastic, I've been busy with stuff. :D
So SideMenu component injects menuActions object automatically to all its own direct children. Here's the code for that. So inside your child component you can access menuActions by using this.props.menuActions.

From that moment you can keep passing menuActions down to child's children components using the following code.

render () {
    var props = this.props;
    return (
        <MyAwesomeChild menuActions={props.menuActions}/>
    );
}

Or using es7 spread feature like this:

render () {
    var props = this.props;
    return (
        <MyAwesomeChild {...props}/>
    );
}

I might be wrong but based on my experience, I don't like to pass these actions down to hierarchy of children. I usually use flux, reflux architectures for doing these type of systems. But again it's your choice! :P Remember, we are still finding a lot of good patterns for writing apps using React.

from react-native-side-menu.

kevinaltschuler avatar kevinaltschuler commented on August 23, 2024

oh awesome! I actually moved the event I was worried about to flux in the mean time but this is super helpful regardless!

from react-native-side-menu.

kevinaltschuler avatar kevinaltschuler commented on August 23, 2024

Actually I have one more issue if you have the time. I'm actually trying to pass menuactions into the firstroute. More specifically, into the leftCorner button that I'm giving to firstroute. any ideas?

from react-native-side-menu.

Kureev avatar Kureev commented on August 23, 2024

@Kevtastic Not sure I got your second question about passing menuActions into initial route, but if I got it correct, you need to use this.props.menuActions in the first-level children. Like if you have

class SomeComponent extends Component

as a content-view /menu-view, and something inside it should use menuActions, you can just access them via this.props.menuActions but it works only for first-level children. I'll try to move it to context ASAP, mb @alinz would be also interested in that.

from react-native-side-menu.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.