@@ -22,8 +22,8 @@ export type Props = {
2222 wrapperStyle ?: object ,
2323 promptStyle ?: object ,
2424 inputStyle ?: object ,
25- history : Array < string > ,
26- onAddHistoryItem : ( entry : string ) => void ,
25+ history ? : Array < string > ,
26+ onAddHistoryItem ? : ( entry : string ) => void ,
2727}
2828
2929type State = {
@@ -48,7 +48,6 @@ export default class ReactConsole extends React.Component<Props, State> {
4848 wrapperStyle : { } ,
4949 promptStyle : { } ,
5050 inputStyle : { } ,
51- history : [ ] ,
5251 } ;
5352
5453 state = {
@@ -67,9 +66,11 @@ export default class ReactConsole extends React.Component<Props, State> {
6766 output : [ welcomeMessage ] ,
6867 } )
6968 }
70- this . setState ( {
71- historyPosition : this . props . history . length ,
72- } )
69+ if ( this . props . history !== undefined ) {
70+ this . setState ( {
71+ historyPosition : this . props . history . length ,
72+ } )
73+ }
7374 }
7475
7576 public clear = ( ) => {
@@ -87,15 +88,17 @@ export default class ReactConsole extends React.Component<Props, State> {
8788 */
8889 private getReverseHistory = ( ) : Array < boolean > => {
8990 const { reverseSearchString} = this . state ;
90- return this . props . history . map ( entry => ( reverseSearchString === undefined || reverseSearchString === '' ) ?
91- // @ts -ignore
92- false : entry . includes ( reverseSearchString ) )
91+ return this . props . history === undefined ?
92+ [ ]
93+ : this . props . history . map ( entry => ( reverseSearchString === undefined || reverseSearchString === '' ) ?
94+ // @ts -ignore
95+ false : entry . includes ( reverseSearchString ) )
9396 } ;
9497
9598 /**
9699 * Takes current text of a main input and generates a string that will be outputted as a log.
97100 */
98- private getCurrentTextSnapshot = ( ) : string => {
101+ private getCurrentTextSnapshot = ( ) : string => {
99102 const { prompt} = this . props ;
100103 const inputString : string = this . state . input ;
101104 return `${ prompt } \xa0${ inputString } ` ;
@@ -269,6 +272,9 @@ export default class ReactConsole extends React.Component<Props, State> {
269272 * @param historyPosition
270273 */
271274 private setPreviewPosition = ( historyPosition : number ) => {
275+ if ( this . props . history === undefined ) {
276+ return
277+ }
272278 this . setState ( {
273279 historyPosition,
274280 input : this . props . history [ historyPosition ] || '' , // if an element history is out of bounds, we just set ''
@@ -354,11 +360,16 @@ export default class ReactConsole extends React.Component<Props, State> {
354360 this . setPreviewPosition ( historyPosition ) ;
355361 event . preventDefault ( )
356362 } else if ( event . which === 40 ) {
363+ if ( this . props . history === undefined ) {
364+ return
365+ }
357366 const historyPosition = Math . min ( this . props . history . length , this . state . historyPosition + 1 ) ;
358367 this . setPreviewPosition ( historyPosition ) ;
359368 event . preventDefault ( )
360369 } else if ( event . which === 82 && event . ctrlKey ) { // ctrl + r
361- console . log ( 'reverse search mode' ) ;
370+ if ( this . props . history === undefined ) {
371+ return
372+ }
362373 this . onReverseSearch ( )
363374 } else if ( event . which === 67 && event . ctrlKey ) { // ctrl + c
364375 this . setState ( {
0 commit comments