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

using LINK functionality in the Sidebar.Menu.Item #7

Closed
dchan14 opened this issue Apr 16, 2017 · 4 comments
Closed

using LINK functionality in the Sidebar.Menu.Item #7

dchan14 opened this issue Apr 16, 2017 · 4 comments

Comments

@dchan14
Copy link

dchan14 commented Apr 16, 2017

is there a way we can use react routers LINK component instead of href?
i like the look of sidbar.menu.item but doing a href call seems to refresh the whole page but if I use link it only replaces the main component which is much nicer.

thanks for your any guidance!

@zksailor534
Copy link
Owner

I've been trying to keep the dependencies for this component to a minimum, otherwise I probably would have used react-router <Link \>. Instead, the method I recommend is making use of the onClick property to pass something like a react-router push. I've used that on a project I was working and it eliminated the effect you mentioned.

@dchan14
Copy link
Author

dchan14 commented Apr 17, 2017

I tried this
<Sidebar.Menu header="MAIN NAVIGATION" key="3"> <Sidebar.Menu.Item icon={{ className: 'fa-calendar' }} title="Calendar" onClick={browserHistory.push('/scheduled')} /> </Sidebar.Menu>

but i get errors -- Cannot update during an existing state transition (such as within render or another component's constructor). Render methods should be a pure function of props and state; constructor side-effects are an anti-pattern, but can be moved to componentWillMount.

@dchan14
Copy link
Author

dchan14 commented Apr 18, 2017

again this is an awesome react-adminLTE dashboard!!

just in case any other beginners need it. i imported browserhistory and
onClick={() => browserHistory.push('/scheduled')} the key was this thing () => bc i was getting ReactJS: Warning: setState(…): Cannot update during an existing state transition ...
i am using react router 3 with vulcanjs !!!

@zksailor534
Copy link
Owner

Glad you could make it work for you.

You are correct, you need to provide a function to events like onClick (or onBlur, etc) instead of a function call. The function call would be activated while rendering the page, causing the error you were seeing. You can either use onClick={() => browserHistory.push('/')} or onClick={function() {browserHistory.push('/')}}.

Closing this issue as solved.

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