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

SFCCounterConnectedExtended does not work in examples #25

Closed
29er opened this issue Nov 3, 2017 · 6 comments
Closed

SFCCounterConnectedExtended does not work in examples #25

29er opened this issue Nov 3, 2017 · 6 comments

Comments

@29er
Copy link

29er commented Nov 3, 2017

The initialCount property does not work on the SFCCounterConnectedExtended component.

import * as React from 'react';

import { SFCCounterConnectedExtended } from '@src/connected';

export default () => (
  <SFCCounterConnectedExtended
    label={'SFCCounterConnectedExtended'}
    initialCount={10}
  />
);

the initalCount is not read into the props because you are using the SFCCounter. What would be your recommendation on fixing this, create a new component or interface ?

@piotrwitek
Copy link
Owner

piotrwitek commented Nov 3, 2017

Hi @29er
This was really a contrived example from top of my head, thank's for pointing that out.
After looking at this, it should be rather like below to make sense (I'll do an update to the guide):

export interface SFCCounterConnectedExtendedProps {
  initialCount: number,
}

const mapStateToProps = (state: RootState, ownProps: SFCCounterConnectedExtendedProps) => ({
  // if redux store value is undefined, use initialCount to initialize 
  count: state.counters.sfcCounter || ownProps.initialCount,
});

export const SFCCounterConnectedExtended = connect(mapStateToProps, {
  onIncrement: actionCreators.incrementSfc,
})(SFCCounter);

I know that's not really a precise answer to your question but for this particular example using SFCCounter the solution make sense and should work.

Maybe you can provide a different example for your specific use case if it does not answer your question.
Cheers!

@29er
Copy link
Author

29er commented Nov 4, 2017

Yep that makes perfect sense. thanks! I am just learning Typescript for the first time and this has been an excellent repo to find. At this point even the simplest things are tripping me up. So thanks : ) . I'd love to see an actual component implementation of the Todos !

@piotrwitek
Copy link
Owner

@29er cool, I'll close the ticket.

About Todos implementation, seems like a nice idea. I'll try to add it in the future.

piotrwitek added a commit that referenced this issue Nov 5, 2017
@29er
Copy link
Author

29er commented Nov 6, 2017

Thanks Piotr ,so what I don't understand, is even after I change the example , when I create the component like so
<SFCCounterConnectedExtended label={'SFCCounterConnectedExtended'} initialCount={10} /> the initial count is 10 as expected. However if I click on Increment, the number goes to 1 ?

const mapStateToProps = (state: RootState, ownProps: SFCCounterConnectedExtendedProps) => ({
count: state.counters.sfcCounter || ownProps.initialCount,
});

This should set the state 'count' to 10, and should be 11 on the next onIncrement, I would have thought !

Can you explain how you would fix this in your example ? Thanks !

@piotrwitek
Copy link
Owner

@29er The problem is we do not update the store with this initial value on component mount event, we only show it as a default when the store value is 0, which is kind of naive implementation.

Need to rethink this example again, give me a moment hehe :)
Thanks for a feedback.

@piotrwitek piotrwitek reopened this Nov 6, 2017
@piotrwitek
Copy link
Owner

@29er fixed, now it should add or subtract a initial value from state so increment will work just fine the same for initial value

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