Ramda
関数内の値が "state"になっているものを使いたいと思います。これは "AND"フィルタと同様に動作します。したがって、1つの値、または複数の値を受け取ることがあります。Ramadを使ってReactを使って配列を渡す
コンポーネントからのデータをこのramda関数に渡すにはどうすればよいですか?
stateで設定されている値を追加するために、 'ramda'をどのようにループすることができますか?
は私もcodepenにこれを追加しました:https://codesandbox.io/s/3OGK2pP9
const AndFilter = pipe(
prop('movies'),
filter(
both(
// Example data to show how it should arrive from the react component.
where({ genres: pipe(pluck('name'), contains('foo')) }),
where({ genres: pipe(pluck('name'), contains('bar')) }),
where({ genres: pipe(pluck('name'), contains('baz')) }),
),
),
);
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
movies: dataTest,
selectedFilters: { foo, bar, baz },
};
}
AndFilter =() => {
this.setState({ movies: AndFilter(x) });
};
render() {
return (
<div>
<button onClick={this.AndFilter}>test</button>
{this.state.movies.map(movies => (
<li key={movies.id}> {movies.name} </li>
))}
</div>
);
}
}
もっと包括的な例を教えてください。おそらく私のペンに?私は成功することなくそれを実装しようとしました。 https://codesandbox.io/s/3OGK2pP9 – Ycon
ok one moment .... –
私はまだフォローしていません。あなたの例は構造の異なるデータのためのものであり、 'ramda'フィルタの方法も異なっています。あなたはここでそれをしてくださいできますかhttps://codesandbox.io/s/J6WW5BD9l?私は変数が 'AndFilter' constに渡されているのを見ません。 – Ycon