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

navigation (component) how to manage internal state? #353

Open
onadeem1 opened this issue Feb 28, 2020 · 3 comments
Open

navigation (component) how to manage internal state? #353

onadeem1 opened this issue Feb 28, 2020 · 3 comments

Comments

@onadeem1
Copy link

onadeem1 commented Feb 28, 2020

Could you guys list some examples for the components. Is it possible to pull in the component as is and then edit what you would like. For example if I wanted the NavigationNext component and I wanted to change what the function does. Lets say something like jump by two slides, how do you alter the functionality.

This what the docs say.
<NavigationNext />
Button allowing the user to navigate to the next view. Accepts an onClick function.

What does it mean accepts the onClick function and can I change the functionality.

If anyone could give a very short example that would be great. Thank you.

@onadeem1 onadeem1 changed the title navigation (component) clarity navigation (component) clarity ex. jump by two Feb 28, 2020
@onadeem1
Copy link
Author

onadeem1 commented Feb 28, 2020

I am not exactly sure what the code should be and am confused by the "accepts onClick function" where should that go? Basically want to achieve something like this. This doesn't work but just to get the idea.

const NavigationNextCustom = ({ innerProps, currentIndex }) => {
    return (
      <div {...innerProps}>
        <button onClick={() => currentIndex = currentIndex + 2}>
          Jump by two
        </button>
      </div>
    )
  }

@onadeem1
Copy link
Author

onadeem1 commented Feb 29, 2020

Sorry I think to be clearer I am asking since the carousel state is being maintained internally (correct me if that is wrong) how do we modify what clicking the previous or next button does?

@onadeem1 onadeem1 changed the title navigation (component) clarity ex. jump by two navigation (component) how to manage internal state? Feb 29, 2020
@eyea
Copy link

eyea commented Mar 20, 2020

2 points.
The first is that you can't change the value of the currentIndex directly. (as far as I can see)
And the solution I want to share to you:

// index.js
@inject(stores => ({
	current: stores.box.current,
        handleJumpTo: stores.box.handleJumpTo
}))

@observer
export default class PreviewImage extends React.Component {
const NavigationNextCustom = ({ ...props }) => {
    return (
      <div >
        <button onClick={() => this.props.handleJumpTo('next', 2)}>
            Jump by two
        </button>
      </div>
    )
  }
 render() {
  <Carousel
    ...props,  
    currentIndex={current}
  >
  </Carousel>
 }
}

// mobx.js
class box {
  @observable current = 0 // defalut value
  @action handleJumpTo(direction, steps) {
      if(direction==='next') {
         // of course, there are some controls before we jump :)
           self.current += steps
     }
  }
}

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