2017-10-23 1 views
0

여분의 소품을 올바르게 전달하는 방법은 무엇입니까?TypeScript with Redux 연결 여분의 소품

const SideBar = connect(
    (state: State) => ({current: state.projects.current}), 
    null 
)(({className, current}) => (
    <nav className={'side-bar ' + className}> 
    ... 
    </nav> 
)) 

나는이 오류가있어 클래스 이름

<SideBar className="app__sidebar"/> 

를 전달하려는 : 내가 생각

(37,24): error TS2339: Property 'className' does not exist on type 
    'IntrinsicAttributes & IntrinsicClassAttributes<Component<Pick<{ 
     current: Project | undefined; } &...'. 

답변

3

을, 문제는 mapStateToProps 기능에 ownProps를 사용하고 클래스 이름 소품을 통과해야한다는 것입니다 구성 요소 분명히

function mapStateToProps(state: State, ownProps) { 
    return { 
    current: state.projects.current, 
    className: ownProps.className 
    } 
} 

const SideBar = connect(mapStateToProps, null)(({className, current}) => (
    <nav className={'side-bar ' + className}> 
    ... 
    </nav> 
)) 
+0

부 내가 ownProps를 지정하고 싶지 않은 것은 무엇입니까? 나는 JS에서 그것을 할 수있다. –