Skip to content

Commit a59155c

Browse files
author
jim
committed
add default values
1 parent 459eb5d commit a59155c

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

Diff for: demo/src/index.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,19 @@ class Demo extends Component {
1515
return <div>
1616
<h1>react-props-editor Demo</h1>
1717
<div>-----Prop Names-------</div>
18-
<ReactPropsEditor onChange={({propValues})=>{
18+
<ReactPropsEditor
19+
onChange={({propValues})=>{
1920
this.setState({propValues})
20-
}} propObjects={{
21-
name: PropObjects.string,
21+
}}
22+
defaultValues={{
23+
name: 'sdfwer'
24+
}}
25+
propObjects={{
26+
name: PropObjects.string.render(
27+
({onChange, propValues})=>{
28+
return <input type='text' value={propValues.name}
29+
onChange={e=>onChange(e.target.value)}/>
30+
}),
2231
location: PropObjects.string.render(({
2332
onChange,
2433
propValues

Diff for: src/PropsEditor.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ function toJsonOpts(options){
2727
})
2828
}
2929

30-
function cleanState(state){
31-
const changedProps = Object.assign({},state);
30+
function cleanState(state, defaultValues){
31+
const changedProps = Object.assign({}, defaultValues, state);
3232
delete changedProps.propsTypes;
3333
delete changedProps.propsTypeOptions;
3434
delete changedProps.propsTypeRender;
@@ -70,6 +70,7 @@ export default class PropsEditor extends Component {
7070
}
7171

7272
render() {
73+
const { defaultValues } = this.props;
7374
const { propsTypes, propsTypeOptions, propsTypeRender } = this.state;
7475
if (!propsTypes) {
7576
return <div>loading...</div>
@@ -90,7 +91,7 @@ export default class PropsEditor extends Component {
9091
await this.setState({[pKey]:value});
9192
return this.triggerChange()
9293
},
93-
propValues:cleanState(this.state)
94+
propValues:cleanState(this.state, defaultValues)
9495
})}</div>
9596
})}
9697
</div>

0 commit comments

Comments
 (0)