ui-router / redux

UI-Router plugin for Redux integration
MIT License
12 stars 6 forks source link

Parameter example? #2

Closed trevor-ryan-burkholder closed 6 years ago

trevor-ryan-burkholder commented 6 years ago

Can we get an example of how to use a route parameter to filter props in a component? e.g. filter todos by whether they're completed or not?

Or would the ui-router/react examples suffice for this?

elboman commented 6 years ago

You don't need to use ui-router/redux to achieve this, unless I'm missing something.

You can read the params via the transition prop that is injected in the routed component like this:

render () {
    const params = this.props.transition.params();
    return (
        <div>
            {todos.filter(todo => todo.status === params.status).map(todo => (
                <Todo data={todo} key={todo.id} />
            ))}
        </div>
    );
}
trevor-ryan-burkholder commented 6 years ago

Thanks! I'll give this a try. I wasn't sure if the transition prop was only necessary if you were doing animations.

elboman commented 6 years ago

Yeah, the transition prop refers to the router transition and not animations of any kind