Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using material-ui with redux?

I'm currently rendering main component this way:

 ReactDOM.render(
      <Provider store = {store}>
        {getRoutes(checkAuth)}
      </Provider>,
      document.getElementById('app')
    )

the docs state to use MuiThemeProvider to wrap my app component. I am alrady using Provider to wrap, any suggestions as to how to use material-ui ina redux app. I am trying to add material-ui in a redux-form Field as below:

import React, { PropTypes } from 'react'
import {default as ReactModal} from 'react-modal'
import {Field, reduxForm} from 'redux-form'
import {TextField} from 'material-ui'

const customStyles = {
  overlay: {
    position: 'fixed',
    top: 0,
    left: 0,
    right: 0,
    bottom: 0,
    backgroundColor: 'rgba(0, 0, 0, 0.55)'
  },
  content: {
    top: '50%',
    left: '50%',
    right: 'auto',
    bottom: 'auto',
    marginRight: '-50%',
    transform: 'translate(-50%, -50%)'
  }
}

const modalForm = (props) => {
  // console.log(props)
  const { handleSubmit, pristine, reset, submitting } = props
  return (
    <div>
      <button onClick= {props.openModal}>Duck</button>
      <ReactModal
      isOpen={props.isOpen}
      style={customStyles}
      onRequestClose={props.closeModal}>

  <h1>Compose New Duck</h1>
  <form onSubmit= {handleSubmit}>
  <label>duck</label>
    <Field name ='duck' component = {(duck) =>
      <TextField hintText = 'Enter Duck'
        floatingLabelText = 'Enter Duck here'
        {...duck} />} />

  </form>
  <button onClick= {props.closeModal}>Close Modal...</button>
</ReactModal>
    </div>
  )
}

export default reduxForm({
  form: 'duckModal'  // a unique identifier for this form
})(modalForm)
like image 652
jasan Avatar asked Jun 22 '16 02:06

jasan


2 Answers

Tried the following and it worked:

 const App = () => (
    <MuiThemeProvider>
      <Provider store = {store}>
        {getRoutes(checkAuth)}
      </Provider>
    </MuiThemeProvider>
    )

  ReactDOM.render(
    <App/>,
  document.getElementById('app')
)
like image 123
jasan Avatar answered Oct 02 '22 09:10

jasan


I would refer you to this example.

like image 26
Erik R. Avatar answered Oct 02 '22 09:10

Erik R.